js一键复制
2020-10-09 本文已影响0人
无题syl
点击按钮 实现一键复制
async copy() {
let { data } = await this.$api.getUnSubmitStuList({
taskID: this.objectId,
})
if (data.status == 1) {
let text = document.createElement('textarea') //如果内容里有空格 要用多文本标签 用input标签不行
//text.setAttribute('readonly', 'readonly')
text.value=data.data
document.body.appendChild(text)
text.select()
if (document.execCommand('copy')) {
document.execCommand('copy')
this.$alert.success('复制成功')
}
document.body.removeChild(text)
//console.log(data.data)
}
},