vue使用clipboard实现复制功能

1、安装

npm install clipboard --save

2、引用

import Clipboard from 'clipboard';

3、复制固定内容




copy() {
     let clipboard = new Clipboard("#copy-btn");
     let that = this;
     clipboard.on("success", function (e) {
           that.$message.success("复制成功");
     });
     clipboard.on("error", function (e) {
           that.$message.error("复制失败");
     });
})

4、复制动态内容

这是复制的内容




copy() {
     let clipboard = new Clipboard("#copy-btn");
     let that = this;
     clipboard.on("success", function (e) {
           that.$message.success("复制成功");
     });
     clipboard.on("error", function (e) {
           that.$message.error("复制失败");
     });
})

你可能感兴趣的:(vue.js,前端,javascript)