關(guān)鍵詞: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('分享內(nèi)容復(fù)制成功');
clipboard.destroy();
});
clipboard.on('error', e => {
this.$message.error('分享內(nèi)容復(fù)制失敗');
clipboard.destroy();
});
}
}
}
參考鏈接
https://segmentfault.com/a/1190000020651289?utm_source=tag-newest