main.js 引入 Clipboard
npm install --save v-clipboard
import Clipboard from ‘v-clipboard‘
Vue.use(Clipboard)
来源链接: https://blog.csdn.net/weixin_39907729/article/details/89211669
<!-- #ifdef H5 --> <text class="item-btn" v-clipboard:copy="member_id" v-clipboard:success="(type) => onCopyResult(‘success‘)" v-clipboard:error="(type) => onCopyResult(‘error‘)">复制 </text> <!-- #endif --> <!-- #ifdef APP-PLUS || MP-WEIXIN --> <text class="item-btn" @click="paste(member_id)">复制</text> <!-- #endif -->
paste(value) { console.log(value,"111111111") uni.setClipboardData({ data: value, success: function () { console.log(‘success‘); } }); }, onCopyResult(type) { console.log(type) if (type===‘success‘) { uni.showToast({ title:"复制成功", icon:"none" }) console.log("复制成功") } else { console.log("复制失败") } },