复制功能

好长时间没写过了,随手写一个吧,证明俺还是程序元。

HTML:

<div class="info_right">
          <h6 class="invitation_tit">
            {{$t('anquan.tuiguang[27]')}}
            <!-- <span
              class="yaoqing_code"
            >{{$t('anquan.tuiguang[27]')}}:{{myInfo.invitationCode}}</span> -->
          </h6>
          <el-input id="link" v-model="myInfo.invitationCode" readonly />
          <span class="copy" @click="copy('link')">{{$t('fiatOrder.main[38]')}}</span>
          <!-- 复制链接 -->
        </div>

js:

//复制信息
    copy(whitch) {
      var _this = this;
      var ele = document.getElementById(whitch);
      ele.select();
      document.execCommand("Copy");
      _this.$public.msg(_this.$t("anquan.tuiguang[16]"), "success", _this); //复制成功
    },

原文地址:https://www.cnblogs.com/wy120/p/11523462.html