100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 【微信小程序-原生开发】富文本编辑器 editor 的使用教程

【微信小程序-原生开发】富文本编辑器 editor 的使用教程

时间:2019-04-06 23:29:19

相关推荐

【微信小程序-原生开发】富文本编辑器 editor 的使用教程

表单内容较多时,通常需要输入换行的数据,此处便需要用到富文本编辑器

富文本编辑器的渲染

<editor class="editorStyle" style="height:auto" id="editor" placeholder="请输入内容" bindready="onEditorReady" bindinput="contentChange"></editor>

.editorStyle {border: 1rpx solid rgb(235, 229, 229);border-radius: 10rpx;padding: 30rpx;margin: 30rpx auto;width: 96%;box-sizing: border-box;}

// 当富文本编辑器挂载完成时执行onEditorReady() {let that = this// 修改时,反显数据this.createSelectorQuery().select("#editor").context((res) => {res.context.setContents({html: that.data.formData.content,});}).exec();},

效果为

// 富文本编辑器内容变化时,同步更新表单字段内容 formData.contentcontentChange(e) {let contentHtml = e.detail.htmlthis.setData({'formData.content': contentHtml})},

富文本内容的渲染

因富文本内容是包含 html 标签的数据,无法直接在微信小程序中渲染,需放入 rich-text 中

<view class="contentBox"><rich-text nodes="{{detail.content}}"></rich-text></view>

.contentBox {padding: 30rpx;/* 文本分散对齐 */text-align: justify;}

效果如下:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。