The applet realizes the function of clicking and copying text

How to implement click copy link or text function in applet
1. wxml

 <view class="erweima" bindtap="open" data-text="82889999-3394"></view >

2、js

 open(e){
    console.log(e.currentTarget.dataset.text);
    wx.setClipboardData({//复制文本
      data: e.currentTarget.dataset.text,
      success: function (res) {
        wx.getClipboardData({//获取复制文本
          success: function (res) {
            wx.showToast({
              title: '复制成功',
              icon:"none",//是否需要icon
              mask:"true"//是否设置点击蒙版,防止点击穿透
            })
          }
        })
      }
    })
  },

insert image description here
it's ok

Created a new group, welcome everyone to join the group discussion 459358760

Guess you like

Origin blog.csdn.net/xiaokangna/article/details/122428830#comments_23009319