//安装clipboard.js
//npm install --save clipboard.js
<template>
<div>{{ params}}</div>
<el-button size="small" class="btn">复制</el-button>
</template>
<script>
import Clipboard from 'clipboard'
export default {
data() {
return {
params: '测试复制',
}
},
mounted() {
//复制
let that = this;
const clipboard = new Clipboard(".btn", {
text: function () {
return that.params
},
});
clipboard.on("success", function (e) {
that.$message.success("复制成功");
});
clipboard.on("error", function (e) {
that.$message.error("复制失败");
});
}
}
</script>
标签:复制到,function,vue,Clipboard,clipboard,params,复制,剪切板
From: https://www.cnblogs.com/LiZiheng/p/17989810