代码如下:
<span id="copy-title">新会员尊享待遇</span>
<el-button type="text" @click="copy('copy-title')">复制标题</el-button>
methods: {
copy(id) {
var text =document.getElementById(id).innerText;
var input = document.createElement('textarea');
input.value = text
input.id = 'copyInput'
document.getElementsByTagName('body')[0].appendChild(input);
document.getElementById('copyInput').select();
if (document.execCommand('copy')) {
this.$message.success('复制成功');
}
document.getElementById('copyInput').remove()
}
}