zoukankan      html  css  js  c++  java
  • vue中实现浏览器的复制功能

      

    点击复制,就可以实现copy

    <p class="inline-block">
    <span >{{fenxiao.appSecret}}</span>
    <span style="color: #0000FF;cursor: pointer" @click="copyAppSecret">复制</span>
    </p>
    copyAppSecret() {
    let createInput = document.createElement("input");
    createInput.value = this.fenxiao.appSecret;
    document.body.appendChild(createInput);
    createInput.select(); // 选择对象
    document.execCommand("Copy"); // 执行浏览器复制命令
    createInput.style.display = "none";
    this.$message({ message: "复制成功", type: "success" });
    },

    网上说的那种
    let tt=document.getElementById("xxxx")
    tt.select(); // 选择对象 
     document.execCommand("Copy"); // 执行浏览器复制命令 
    这种不行

    文本是没有select方法的,input才有 所以要先创建input元素,在添加值,在赋值,

    亲测有效,换成el-input就能行

  • 相关阅读:
    JVM五大知识点
    VIM命令
    JVM之GC算法
    SpringMVC之搭建框
    Mybatis之延迟加载机制
    分页查询
    Mybatis之占位符与拼接符
    == 和 equal
    LAMBDA表达式常用 (全)
    Jquery 时间格式化
  • 原文地址:https://www.cnblogs.com/myfirstboke/p/10469584.html
Copyright © 2011-2022 走看看