97-liu

导航

js的复制功能

HTML:

 <van-row
          v-for="(item, index) in numberList"
          :key="index"
          type="flex"
          justify="start"
          align="center"
          class="d-n-item"
        >
          <span style="margin-right: 0.2rem">{{ item }}</span>
          <span class="d-copy" @click.prevent="copyShaneUrl(item)">复制</span>
   </van-row>

js:

    numberList = ["2109282324070172523888", "1654asdc1s32d1fs32d1g"];
   
  copyShaneUrl(value: string): void {
    var input = document.createElement("input"); // 直接构建input
    input.value = value; // 设置内容
    document.body.appendChild(input); // 添加临时实例
    input.select(); // 选择实例内容
    document.execCommand("Copy"); // 执行复制
    document.body.removeChild(input); // 删除临时实例
  }

 

posted on 2022-04-06 14:44  大圣爱打猪八戒  阅读(79)  评论(0编辑  收藏  举报