<template>
<div>
<button @click="copy">点击复制</button>
</div>
</template>
<script>
export default {
name: 'CopyTest',
data() {
return {
copyContent: '这是复制的内容'
}
},
methods: {
copy() {
navigator.clipboard.writeText(this.copyContent)
.then(() => window.alert('内容已添加到系统剪贴板'))
.catch(()=> window.alert('复制失败'));
}
}
}
</script>