介绍
微信小程序里,通过使用 wx.setClipboardData
实现点击按钮复制订单信息,如下图所示:
wxml
<view class="code copyCode">订单编号:{{details.orderNO}}
<button @tap.stop="copyOrder">复制</button>
</view>
wxss
.copyCode
display: flex
flex-direction: row
justify-content: flex-start
button
width: 60px
height: 36px
border-radius: 20px
font-size: 18px
color: #F78B43
line-height: 36px
background: #f4f4f8
margin-left: 20px
js
data() {
return {
datails.orderNO: 'L12345565669'
}
},
methods: {
// 复制订单编号
copyOrder() {
uni.setClipboardData({
// data里放,需要复制的数据
data: this.details.orderNO,
success: (res) => {
this.$ls.toast('复制成功')
}
})
},
}
如下图所示,表示复制信息成功