本文共 422 字,大约阅读时间需要 1 分钟。
一、在main.js文件中引入和使用复制包(全局使用)
import VueClipboard from 'vue-clipboard2' //复制Vue.use(VueClipboard);
二、使用
避免两个this冲突
1、 this变量 不要乱放,最好永远放在所在闭包的 第一行,使用const 声明
2、vue实例的上下文推荐命名: vm
/** 点击复制 */clickCopy(e) { const vm = this; //console.log(e.target.innerText) let copyText = e.target.innerText; this.$copyText(copyText).then(function (res) { console.log(res.text); if(res.text){ vm.msgSuccess("复制成功"); } });}
三、
转载地址:http://xjwq.baihongyu.com/