进入了三次页面, 点击复制成功了三次
上代码~~
mounted () {
let _this
= this
_this
.clipboard
= new Clipboard('.copy-link')
_this
.clipboard
.on('success', function (e
) {
_this
.$message
.success('复制成功', 500)
e
.clearSelection()
})
_this
.clipboard
.on('error', function (e
) {
_this
.$message
.error('复制成功', 500)
})
}
因为每次进页面的时候都会new一个Clipboard, 所以每次都会多new出一个
解决方案:
页面退出时销毁这一实例
destroyed () {
this.clipboard
.destroy()
},
转载请注明原文地址: https://mac.8miu.com/read-487173.html