npm install vue-clipboard2 --save
全局注入
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)
<div class="tool-text mar no-mart">报名地址</div>
<el-row class="detail tool-send">
<el-col :span="20">
<div class="grid-content bg-purple-light">{{message}}</div>
</el-col>
<el-col :span="4" style="text-align:right;">
<button v-clipboard:copy="message" v-clipboard:success="onCopy" v-clipboard:error="onError" class="copy-button">复制</button>
</el-col>
</el-row>
// 复制成功时的回调函数
onCopy(e) {
this.$message({
message: '地址复制成功',
type: 'success'
});
},
// 复制失败时的回调函数
onError(e) {
this.$message.error('地址复制失败');
},