在vue中使用clipboard.js 時(shí)候發(fā)現(xiàn)一個(gè)問題塔嬉,如果移動(dòng)端不是input或者button码邻,則復(fù)制不成功,使用步驟如下
1. 引入clipboard.js
npm install clipboard --save
2. 在需要使用的組件中import
import Clipboard from 'clipboard';
3. 添加需要復(fù)制的內(nèi)容
<button class="tag-read" data-clipboard-text="復(fù)制" @click="copy">復(fù)制內(nèi)容</button>
4.copy() {
let clipboard = new Clipboard('.tag-read')
clipboard.on('success', e => {
console.log('復(fù)制成功')
// 釋放內(nèi)存
clipboard.destroy()
})
clipboard.on('error', e => {
// 不支持復(fù)制
console.log('該瀏覽器不支持自動(dòng)復(fù)制')
// 釋放內(nèi)存
clipboard.destroy()
})
}