app中使用,框架用的是vue.js
1.显示要下载这个Clipboard.js插件
2. package-lock.json里面
"clipboard-polyfill": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/clipboard-polyfill/-/clipboard-polyfill-2.3.0.tgz",
"integrity": "sha1-IQMYRMHsJLOat5QNuh6whgE0vlk=",
"requires": {
"es6-promise": "4.1.1"
}
},
3.在要做复制功能的页面
template
<div class="copy-number" @click.stop="copyBankNum(cardItem.bankCardNo)">复制</div>
import clipboard from 'clipboard-polyfill'
copyBankNum (cardNum) {
if (this.GLOBAL.isInApp) {
window.JSBridge.copyToClipboard(cardNum) //这里一定要传哦,不然会显示undefined
} else {
alert(cardNum)
clipboard.writeText(cardNum)
Toast({
iconClass: 'icon icon-success',
message: '复制成功',
duration: 500
})
}
}