安装
npm i vue-clipboard2 -S
引入main.js
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard )
在使用的页面调用
<span class="icon-button icon-button-serve" title="双击复制服务地址" @dblclick="copyUrl(scope.row.trueUrl)"></span>
// 双击复制服务地址 str {String} 服务地址url
copyUrl(str){
this.$copyText(str)
.then(e=>{
this.$message({type:'success',message:`服务地址 ${str} 已复制到剪贴板`,showClose:true});
},e=>{
this.$message({type:'error',message:`很抱歉,服务地址 ${str} 复制到剪贴板失败`,showClose:true});
})
},