小程序用 rich-text长按复制事件
微信小程序的富文本编辑器 rich-text 没有提供长按出现复制剪切功能,下面是为大家提供的长按实现复制的简单功能,效果没有微信聊天页长按复制的效果好。
1,在 rich-text 表签里添加 bindlongpress=“copy” data-text="{{nodes}}"
<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
}
})
}
});
},
在小程序体验


浙公网安备 33010602011771号