上週的項目中實現兌換功能,用於兌換碼比較複製(英文大小寫+數字),爲方便用戶兌換就實現了點擊複製的功能
效果圖:
實現的代碼:
.wxml頁面:
<view class='commission'>
<view class="number">
{{exchangeKey}}
</view>
<view class="copy" bindtap='copyKey' data-text="{{exchangeKey}}">點擊複製</view>
</view>
.js頁面:
Page({
data:{
exchangeKey:'YJL245sd5f'
},
copyKey: function (e) {
wx.setClipboardData({
data: e.currentTarget.dataset.text,
success: function (res) {
wx.getClipboardData({
success: function (res) {
wx.showToast({
title: '複製成功'
})
}
})
}
})
},
})