<div class="content"></div>
<el-button @click="copy">复制</el-button>
copy() {
let pList = document.querySelectorAll(".content")
let valueList = []
if (pList.length > 0) {
pList.forEach(r => {
valueList.push(r.textContent + '\r\n')
})
valueList = [valueList[valueList.length - 1]]
}
console.log(valueList)
let text = valueList.join('')
let textArea = document.createElement("textarea");
textArea.value = text
document.body.appendChild(textArea);
textArea.select()
document.execCommand('copy')
document.body.removeChild(textArea)
this.$message.success('复制成功!')
},
标签:功能,textArea,js,复制,let,valueList,document,pList
From: https://www.cnblogs.com/LiZiheng/p/18217170