Copy text function in WeChat applet

1. Copy text function of WeChat applet

2. Note: The method is wrapped in view, otherwise the click may fail

wxml

  <view class="invoice-order-item">
    <text>订单编号</text>
    <view  data-text="{
   
   {orderNumber}}" bindtap="copywxtap">{
   
   {orderNumber}}  <text 
    style="color:#777;margin-left:10rpx;">复制</text></view>
  
  </view>

js

    //复制订单号
    copywxtap: function (e) {
      console.log(e.currentTarget.dataset.text)
     wx.setClipboardData({
       data: e.currentTarget.dataset.text,
       success: function (res) {
         wx.getClipboardData({
           //这个api是把拿到的数据放到电脑系统中的
           success: function (res) {
             console.log(res.data) // data
             wx.showToast({
               title: '复制成功',
             })
           }
         })
       }
     })
   },

 

Guess you like

Origin blog.csdn.net/asteriaV/article/details/110930714