vue 点击文字按钮复制相应内容与复制并打开链接

复制链接并打开链接预览

html:

<div class="exchange-code-cont flex-end">
//需要复制的值
        <div class="exchange-code-text">{{ digitalCollectionCode }}</div>
//复制点击的按钮(src为复制图标地址)
        <span @click="copyCode(digitalCollectionCode)" >复制并打开链接</span>
      
      </div>

js:

 

  data() {
    return {
      digitalCollectionCode: 'https://blog.csdn.net/leng0920/article/details/105628352',
    };
  },

 

复制文本内容

HTML:

<div class="exchange-code-cont flex-end">
//需要复制的值
        <div class="exchange-code-text">{{ digitalCollectionCode }}</div>
//复制点击的按钮(src为复制图标地址)
        <span @click="copyCode(digitalCollectionCode)" >复制内容</span>
      
      </div>

 js:

 digitalCollectionCode为需要复制的值,也可以是变量

  data() {
    return {
      digitalCollectionCode: '123456',
    };
  },
  methods: {
    copyCode(digitalCollectionCode) {
        const input = document.createElement("input");
	      document.body.appendChild(input);
	      input.setAttribute("value", digitalCollectionCode);
	      input.select();
	      if (document.execCommand("copy")) {
	        document.execCommand("copy");
	      }
	      document.body.removeChild(input);
        this.$message({
            message: "复制成功",
            type: "success",
          });//饿了么框架提示语
          setTimeout(()=>{
            window.open(digitalCollectionCode,'_blank');
          },400)
    },
  },
  methods: {
    copyCode(digitalCollectionCode) {
      var aux = document.createElement('input');
      aux.setAttribute('value', digitalCollectionCode);
      document.body.appendChild(aux);
      aux.select();
      document.execCommand('copy');
      document.body.removeChild(aux);
      this.$notify({ type: 'success', message: '复制成功' });//引入vant框架可用
    },
  },

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值