关键词:clipboard.js; vue;
从npm安装
npm install clipboard --save
html
<button class="share" :data-clipboard-text="shareText" @click="handleShareClick">分享</button>
js
import Clipboard from 'clipboard'
export default{
data() {
return {
shareText: ''
}
},
methods: {
handleShareClick(){
const clipboard = new Clipboard('.share');
this.shareText= 'hhh'
clipboard.on('success', e => {
this.$message.success('分享内容复制成功');
clipboard.destroy();
});
clipboard.on('error', e => {
this.$message.error('分享内容复制失败');
clipboard.destroy();
});
}
}
}
参考链接
https://segmentfault.com/a/1190000020651289?utm_source=tag-newest
网友评论