功能: 点击按钮复制内容,在输入框中粘贴。
<el-input v-model="text"></el-input>
<el-button @click="copy">复制</el-button>
copy(){
let ipt = document.createElement('input')
ipt.value = '复制内容'
document.body.appendChild(ipt)
ipt.select()
document.execCommand('Copy')
ipt.remove()
this.$message({
message: '复制成功',
type: 'success'
})
}
参考链接:js实现复制功能