1.先安装依赖
npm install --save vue-clipboard2
2.引入
1.vue
import Vue from 'vue'
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)
2.常规引入
<script src="vue.min.js"></script>
<!-- 必须在vue.js之后放置这一行 -->
<script src="vue-clipboard.min.js"></script>
3.使用
<template>
<div class="copyBox">
<span>{{sysAppIds}}</span>
<el-button
type="button"
v-clipboard:copy="sysAppIds"
v-clipboard:success="onCopy"
v-clipboard:error="onError"
>点击复制</el-button>
</div>
</template>
<script>
export default {
data(){
return {
sysAppIds: '8888888'
}
},
methods: {
// 复制成功
onCopy(e){
this.$message.success({
message: "复制成功"
});
},
// 复制失败
onError(e){
this.$message.error({
message: "复制失败"
});
},
}
}
</script>