js原生实现复制文本到剪切板

<span id="copy">{{yuming}}</span>
<el-button type="primary" plain size="mini" @click="copy()">复制</el-button>
copy(){
     var copyTest = document.getElementById("copy").innerText;
     var inputTest = document.createElement('input');
     inputTest.value = copyTest;
     document.body.appendChild(inputTest);
     inputTest.select();
     document.execCommand("Copy");
     inputTest.className = 'oInput';
     inputTest.style.display = 'none';
     alert('复制成功');
    }
原文地址:https://www.cnblogs.com/dongdong1996/p/13881172.html