当前位置:网站首页>小程序editor富文本编辑使用及rich-text解析富文本
小程序editor富文本编辑使用及rich-text解析富文本
2022-07-28 21:54:00 【酱酱的头发还在。】
目录
一、下载
先下载editor的组件
下载地址:https://github.com/jxh1997/Editor
将下载好后的文件放到项目中
二、引入
在需要的用到富文本的组件的json文件中引入:
"usingComponents": {
"richText":"../../components/editor/editor" // 富文本文件的路径
},三、组件的使用
<richText
id='richText'
readOnly='{
{readOnly}}' // 编辑器是否只读
placeholder='{
{placeholder}}'
formatDate='YY/MM/DD'
buttonTxt='保存'
bind:clearBeforeEvent='clearBeforeEvent' //清空编辑器内容之前的回调
bind:clearSuccess='clearSuccess' //清空编辑器内容成功的回调
bind:undo='undo' //撤回内容成功的回调
bind:restore='restore' //恢复内容成功的回调
bind:onEditorReady='onEditorReady' //编辑器初始化完成的时候回调,可以获取组件实例
bind:bindfocus='bindfocus' //编辑器聚焦时触发
bind:bindblur='bindblur' //失去焦点的时候触发
bind:bindinput='bindinput' //编辑器输入中时触发实时返回富文本的内容
bind:insertImageEvent='insertImageEvent' // 插入图片按钮点击时回调
bind:getEditorContent='getEditorContent' //保存按钮点击时回调,返回富文本内容
>
</richText>四、解析富文本
因为我们要展示的是html文件,因此我们需要利用组件来进行解析再展示:
<rich-text nodes="{
{html}}" ></rich-text> this.setData({
html: res.data[0].html.replace('<img ', '<img style="max-width:100%;height:auto;"'),
})其中,后面追加的replace('<img ', '<img style="max-width:100%;height:auto;"'),是为了适配html文件中的图片。因为在富文本中添加的图片,默认会很大。这样设置的话,图片就可以适配。
边栏推荐
- The classic dual stack implementation queue, pay attention to the modification of the judgment conditions of traversing the stack.
- 金仓数据库 KingbaseES V8.3至V8.6迁移最佳实践(2. KingbaseES V8.3和 V8.6 兼容性)
- Custom MVC principle and framework
- 机器学习问题笔记
- 22 Niuke multi school Day1 I - Introduction to chiitoitsu DP
- Runloop principle (I)
- How to add the index of a set in mongodb to another set in mongodb
- JS small method
- [self] - brush questions BFS
- 二舅火了,全网刷屏,他凭什么能治好我的精神内耗?
猜你喜欢

超参数优化(网格搜索和贝叶斯优化)

Development of small programs ①

Achieve high throughput through Wi Fi 7 - insight into the next generation of Wi Fi physical layer

MySQL log management, backup and recovery

Runloop principle (I)

Development of small programs ②

2022 welder (Junior) work license questions and answers

新一代超安全蜂窝电池 思皓爱跑上市13.99万元起售

【自】-刷题-集合

Class, leetcode919 -- complete binary tree inserter
随机推荐
Codeforces Round #474 (Div. 1 + Div. 2) - C, F
Trivy [3] custom scanning strategy
超参数优化(网格搜索和贝叶斯优化)
Rhce第一天
2022G3锅炉水处理考试模拟100题模拟考试平台操作
Go 中的并发 Concurrency
解决线程安全问题&&单例模式
【自】-刷题-字符串
Byte 8 years' experience of female test Director - for girls who want to change careers or are about to enter the testing industry
ACM SIGIR 2022 | 美团技术团队精选论文解读
编译原理研究性学习专题 2——递归下降语法分析设计原理与实现
搭载新一代超安全蜂窝电池,思皓爱跑上市13.99万元起售
MySQL introduction
深度剖析集成学习Xgboost(续)
Pagoda phpMyAdmin unauthorized access vulnerability
Object object
22 Niuke multi school Day1 I - Introduction to chiitoitsu DP
【自】-刷题-动态规划
2022 simulated examination platform operation of hoisting machinery command examination questions
一文读懂Okaleido Tiger近期动态,挖掘背后价值与潜力