Nuxt.js如何实现复制文本内容到粘贴板呢?
估计能找到这里来了,你看到不少文章了吧。或者搜索引擎搜索不到。
不知道你有没有大骂傻逼
Nuxt.js的本质还是js
所以我们通过Js代码来实现吧,引入进来使用即可
创建一个copyUtil.js文件
export default {
  copyContent(text) {
    let target = null;
    target = document.createElement('div');
    target.id = 'tempTarget';
    target.style.opacity = '0';
    target.innerText = text;
    document.body.appendChild(target);
    try {
      let range = document.createRange();
      range.selectNode(target);
      window.getSelection().removeAllRanges();
      window.getSelection().addRange(range);
      document.execCommand('copy');
      window.getSelection().removeAllRanges();
    } catch (e) {
    }
    target.parentElement.removeChild(target);
  }
}
以上亲测有效