x.wxml
<view class="margin-30">
<text>点击下方按钮复制链接地址并用浏览器打开</text>
<text class='shopName' bindtap='textPaste'></text>
<button bindtap="textPaste">点击复制</button>
</view>
*.js
const app = getApp();
Page({
textPaste() {
wx.setClipboardData({
data: '需要复制的内容',
success: function (res) {
wx.getClipboardData({
// 这个api是把拿到的数据放到电脑系统中的
success: function(res) {
console.log(res.data) // data
}
})
}
})
}
})
官方文档:https://developers.weixin.qq.com/miniprogram/dev/api/device/clipboard/wx.setClipboardData.html