vue 点击复制文本内容

1.先安装clipboard     npm install clipboard --save 
2.在main.js中引入并挂载:
    import clipboard from 'clipboard';
    Vue.prototype.clipboard = clipboard
3.在页面中进行使用
<div class="express_info_right" id="express_info_right" data-clipboard-action="copy"
 :data-clipboard-text="order.order_no"  @click="copy">
                    <span>复制</span>
</div>

methods:{
      copy() {
            let clipboard = new this.clipboard("#express_info_right");
            let that = this
            clipboard.on('success', function () {
               //成功时操作
               //在这里,我使用的是vux ui框架进行一些弹层;
                that.$vux.toast.show({
                    type:"success",
                    isShowMask:true,
                    time:1000,
                    text:"已复制",
                    position:"middle"
                })
            });
            clipboard.on('error', function () {
                that.$vux.toast.show({
                    type:"cancel",
                    isShowMask:true,
                    time:1000,
                    position:"middle",
                    text:"复制失败"
                })
            });
          }
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容