复制 文本

<div
          class="text-wrapper"
          style="white-space: pre-wrap; widht: 100%; height: 100%"
          v-html="look2"
          v-if="isShow2"
          id="text2"
        >
          {{ look2 }}
          <el-input v-model="look2" id="input2"> </el-input>
        </div>
      </div>
      <div class="word-button">
        <el-button
          @click="copyText()"
          class="text-button"
          type="primary"
          size="mini"
          >复制量刑信息内容</el-button
        >
 copyText() {
      if (this.isShow1 == true && this.isShow2 == false) {
        console.log(1);
        let text = document.getElementById("text").innerText;
        let input = document.createElement("input"); // js创建一个input输入框
        input.value = text; // 将需要复制的文本赋值到创建的input输入框中,this.look这个是我要复制的内容
        document.body.appendChild(input); // 将输入框暂时创建到实例里面
        input.select(); // 选中输入框中的内容
        document.execCommand("Copy"); // 执行复制操作
        document.body.removeChild(input); // 最后删除实例中临时创建的input输入框,完成复制操作
      } else if (this.isShow1 == false && this.isShow2 == true) {
        console.log(2);
        let text = document.getElementById("text2").innerText;
        let input2 = document.createElement("input2"); // js创建一个input输入框
        input2.value = text; // 将需要复制的文本赋值到创建的input输入框中,this.look这个是我要复制的内容
        document.body.appendChild(input2); // 将输入框暂时创建到实例里面
        input2.select(); // 选中输入框中的内容
        document.execCommand("Copy"); // 执行复制操作
        document.body.removeChild(input2); // 最后删除实例中临时创建的input输入框,完成复制操作
      }
      this.$message({
        message: "复制成功",
        type: "success",
      });
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值