async handleCopyLink(record) {
const url = record.userId
const copyInput = document.createElement('input')
document.body.appendChild(copyInput)
copyInput.setAttribute('value', url)
copyInput.select()
document.execCommand('Copy')
this.$message.success('链接已复制!')
copyInput.remove()
},
先明确自己想要复制的变量
之后创建一个inputdom元素
将创建的dom元素添加到最后
将想要复制的变量设置给input的value值
选中input元素select()
利用document.execCommand('Copy')方法进行复制
进行提示
最后删除创建的inputdom元素
2、通过浏览器进行操作
handleTest() {
let value = '123456789' // 想要复制的值
navigator.clipboard.writeText().then((res) => {
console.log('成功', res);
}).catch((err) => {
console.log(err, '失败');
});
},