Clipboard.js跳出多次复制成功的问题

mac2024-03-24  32

进入了三次页面, 点击复制成功了三次

上代码~~

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() },
最新回复(0)