注意要引入Clipboard
template
<div class="code-main top">
<div class="qrcode" ref="qrCodeUrl"></div>
<p>{{extendUrl}}</p>
<button class="copy" :data-clipboard-text="extendUrl" @click="copy">复制链接</button>
<p>我的邀请码: <span>{{myCode}}</span></p>
</div>
JS
var clipboard = new Clipboard('.copy')
clipboard.on('success', e => {
this.$message.success('复制成功!');
clipboard.destroy()
})
clipboard.on('error', e => {
this.$message.warning('该浏览器不支持自动复制!');
clipboard.destroy()
})