In project development, we often encounter some text copy requirements, such as copying order numbers, copywriting, etc.
1. Long press to copy
To implement the long-press copy function, you need to set the user-select attribute in the text tag
<text user-select="{
{true}}">复制订单号</text>
2. Button copy
is to copy the fixed content to the clipboard
wx.setClipboardData({
data: "复制订单号",
})
After the call is successful, a toast will pop up prompting "the content has been copied" for 1.5s
If you don't use the system's toast bullet box, you can call wx.hiddenloading(), and the toast bullet box that comes with setClipboardData will no longer be displayed
wx.setClipboardData({
data: "复制订单号",
success: function () {
wx.hideLoading()
wx.showToast({
title: '复制成功',
})
}
})