按钮复制文字 vue
HTML:
<p>{{productInfo.goodsTitle}}<a-icon type="copy" @click="copyTitle(productInfo.goodsTitle)" /></p>
JS:
copyTitle (text) {
console.log(text)
this.copyContent = text // 也可以直接写上等于你想要复制的内容
var input = document.createElement('input') // 直接构建input
input.value = this.copyContent // 设置内容
document.body.appendChild(input) // 添加临时实例
input.select() // 选择实例内容
document.execCommand('Copy') // 执行复制
document.body.removeChild(input) // 删除临时实例
this.$message.success('复制成功')
}