vue + clipboard的复制粘贴功能

下载安装

npm install clipboard --save

或者直接在 https://clipboardjs.com/ 下载压缩包,放在 node_modules 下

 

引入

import Clipboard from "clipboard";

函数

copy(e, text) {
    const that = this;
    const clipboard = new Clipboard(e.target, { text: () => text });

    clipboard.on("success", e => {
        that.$message({
            type: "success",
            message: "复制成功"
        });

        // 释放内存
        clipboard.off("error");
        clipboard.off("success");
        clipboard.destroy();
    });

    clipboard.on("error", e => {
        that.$message({
            type: "waning",
            message: "不支持自动复制"
        });

        // 释放内存
        clipboard.off("error");
        clipboard.off("success");
        clipboard.destroy();
    });

    clipboard.onClick(e);
}

使用

@click="copy($event,'/pages/product/detail?id='+scope.row.id+'')"

相关文档

官方地址:https://clipboardjs.com/

Github:https://github.com/zenorocha/clipboard.js/

猜你喜欢

转载自blog.csdn.net/aithena/article/details/88048856
今日推荐