微信扫一扫看面试题

关注面试题库

小程序用 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
				}
			})
		}
	});
},

在小程序体验

在这里插入图片描述

posted @ 2022-07-23 10:03  web前端面试小助手  阅读(860)  评论(0)    收藏  举报