微信小程序我是用的uniapp写的,所以部分API可能和微信小程序原本的不同
<text class="code-id">
<text>會員ID:</text>
<text selectable="true">{{ details.id }}</text>
</text>
<view class="btn">
<button @click="copyBtn" class="code-btn" size="mini" type="default">複製</button>
</view>
copyBtn(e) {
let that = this;
uni.setClipboardData({
//要复制的内容
data: that.details.id,
success: res => {
uni.getClipboardData({
success: res => {
wx.showToast({
title: '複製成功'
});
}
});
}
});
}
1、uni.setClipboardData(OBJECT)
设置系统剪贴板的内容。
OBJECT 参数说明
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
data | String | 是 | 需要设置的内容 |
success | Function | 否 | 接口调用成功的回调 |
fail | Function | 否 | 接口调用失败的回调函数 |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
2、uni.getClipboardData(OBJECT)
OBJECT 参数说明
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
success | Function | 否 | 接口调用成功的回调 |
fail | Function | 否 | 接口调用失败的回调函数 |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
success 返回参数说明
参数 | 类型 | 说明 |
---|---|---|
data | String | 剪贴板的内容 |