不再用 clipboard.js 了,所以:
- 1
- 2
- 3
- 4
- 5
- 6
<!-- 这就是剪贴板载体,想办法视觉隐藏就可以 -->
<input type="text" v-model="clipboardText" class="clipboard-input" ref="clipboard">
<button @click="copyToClipboard('123')"></button>
<button @click="copyToClipboard('abc')"></button>
<button @click="copyToClipboard('789')"></button>
- 1
- 2
- 3
- 4
.clipboard-input {
height: 0px;
opacity: 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
export default {
data() {
return {
clipboardText: ''
}
},
methods: {
copyToClipboard(text) {
console.log('要复制这个文本:', text)
this.clipboardText = text
// $nextTick 在这里没用
setTimeout(() => {
this.$refs.clipboard.select()
document.execCommand('Copy')
})
}
}
}
好,完
console.log('666')
alert('NB');
reply:
爱你
11
reply:
回复1
666666
https://caniuse.com/#search=execCommand
大佬, 太强大了, 👍