1.安装
npm install --save vue-clipboard2
2.在main.js中引用
import Vue from 'vue'
import VueClipBoard from 'vue-clipboard2'
Vue.use(VueClipBoard)
3.代码中使用
<button @click="Copy">复制</button>
Copy() {
this.$copyText(this.value).then(
function(e) {
console.log("copy arguments e:", e);
console.log("复制成功!");
},
function(e) {
console.log("copy arguments e:", e);
console.log("复制失败!");
}
);
}
说明:
this.$copyText是插件自己定义在vue的实例上的在main.js中引入后,即可在全局使用。