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('复制成功'); }
搞了半天,我还以为我会呢