【Vue】12.vue中实现点击复制及打开手机微信APP的功能

最近在做vue项目的时候遇到了这样的一个需求,点击复制微信昵称并打开手机微信的功能,在网上查了一下,vue有一个第三方的插件,考虑到各个浏览器剪切板的兼容性问题,就直接引用了这个插件,打开微信就通过url协议weixin://

可参考vue-clipboard2

<template>
    <div class="landing002-wrapper">
      <div class="landing002-content">
        <div class="landing002-content-description">
          <img class="img-left" src="../../images/landing002/landing002_arrow_down.png"/>
          <span>点此复制小程序名并进入微信</span>
          <img class="img-right" src="../../images/landing002/landing002_arrow_down.png"/>
        </div>
        <div class="landing002-content-word" @click="copyToBoard">点击进入微信</div>
        <div class="landing002-word">一键帮你找出TA的所有问题</div>
      </div>
    </div>
</template>

<script>
  import CONSTANT from '../../common/js/constant';

    export default {
      data() {
        return {
          name: 'Landing002',
          message: CONSTANT.WX_CHAT_NICKNAME,
        };
      },
      methods: {
        copyToBoard() {
          this.$copyText(this.message).then((e) => {
            console.log(this.message);
            console.log(e);
            this.$createToast({
              txt: '微信昵称已复制',
              type: 'txt',
            }).show();
            setTimeout(() => {
              this.goWxchat();
            }, 1000);
          }, (e) => {
            console.log(e);
          });
        },
        goWxchat() {
          window.location.href = 'weixin://';
        },
      },
    };
</script>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值