• 【vue】点击复制到剪贴板的方法( clipboard )


    需求描述:点击复制可以把店铺链接复制到剪贴板上
     
    解决方法:
    使用clipboard 插件
     
    安装
    npm install clipboard --save
     
    设置
    在main.js 中引入, 当然我们也可以在用到的.vue中映入,因为不止在一个地方中用到了拷贝文字
    import clipboard from 'clipboard';//注册到vue原型上Vue.prototype.clipboard = clipboard;
     
     
    在需要拷贝文字的文件里面
    <template>
        <div class="qrCodeContainer">
            <div class="linkContent">
                <a>店铺链接:<span id="qrcode_url">{{qrcode_url}}</span></a>
                <button id='copy' data-clipboard-target='#qrcode_url' @click="copyLink">复制</button>
            </div>
        </div>
    </template>
     
     
    <script>
    import { Toast } from 'mint-ui';
    export default {
        data() {
            return {
                qrcode_url: 'https://www.baidu.com/'
            }
        },
        methods: {
            copyLink() {
                const _this = this;
                const clipboard = new this.Clipboard('#copy');
                clipboard.on('success', () => {
                    Toast({
                        message: '复制成功',
                        duration: 1000
                    });
                })
                clipboard.on('error', () => {
                    Toast({
                        message: '复制失败',
                        duration: 1000
                    });
                })
                console.log(clipboard)
            }
        }
    }
    </script>
     
     
     
  • 相关阅读:
    Delphi-基础(for循环)
    Delphi-基础(运算符)
    Delphi-基础
    python 序列化
    python 模块、包
    time,datetime,random,os,sys,hashlib,logging,configparser,re模块
    第一章.Python环境安装&Pycharm日常使用
    第一章.变量.常量.注释.运算符.if流程控制
    Redis持久化数据介绍&主从复制和哨兵模式环境部署
    Redis缓存应用安装部署&常见的数据类型
  • 原文地址:https://www.cnblogs.com/guanpingping/p/12055733.html
Copyright © 2020-2023  润新知