Vue 实现一键复制的功能

181 阅读1分钟

 做项目遇到需要复制链接进行分享

 解决代码

<el-button class="share" type="text" @click.native="Share">分享</el-button>

方法

methods:{
  Share() {
    let oInput = document.createElement("input");
    oInput.value = '这里填写需要复制的链接';
    document.body.appendChild(oInput);
    oInput.select();
    document.execCommand("Copy");
    oInput.remove();
    this.$notify({
      title: '分享',
      message: '链接复制成功',
      position: 'bottom-right'
    });
  },
}