document.execCommand("copy")复制链接或文本

<div v-if="type != 2" ref="qrcode" :class="['link-code',[manuscript.manuscriptType==2?'link-code-poster':'']]" @click="copyLink" @mouseenter="scaleMax" @mouseleave="scaleMin"></div>
<input id="copyLinkInput" class="copy-input"/>
.link-code {
  position: absolute;
  bottom: 20px;
  left: 0;
  width: 70px;
  height: 70px;
}
.copy-input {
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  z-index: -10;
}
    // 点击二维码复制链接
    copyLink() {
      var _this = this;
      var $linkInput = $('#copyLinkInput');

      $linkInput.val(_this.previewUrl);
      $linkInput.select();
      document.execCommand("copy");
      setTimeout(function () {
          _this.$message.success('复制链接成功!')
      }, 100)
    },



posted on 2020-01-08 15:09  活在当下zql  阅读(5472)  评论(0)    收藏  举报