微信小程序的富文本编辑器 rich-text 没有提供长按出现复制剪切功能,下面是为大家提供的长按实现复制的简单功能,效果没有微信聊天页长按复制的效果好。

步骤:

1,在 rich-text 表签里添加 bindlongpress="copy" data-text="{{nodes[index]}}"

index.wxml

......rich-text nodes="{{nodes[index]}}" class='ctext' bindlongpress="copy" data-text="{{nodes[index]}}" selectable='true'/rich-text......

2,在js文件中写上绑定事件即可

copy: function (e) {var that = this;var text = e.currentTarget.dataset.text;console.log(e);wx.setClipboardData({data: text,success: function (res) {// wx.hideToast();    //打开可不显示提示框wx.getClipboardData({success (res) {console.log(res.data) // data}})}});},

3,最后,再次定位到输入框时,长按即可显示“粘贴”了。

TAG标签: 微信小程序复制微信

http://www.xiaochengxub.com/read-105196.html