[微信小程序] rich-text富文本
来源:互联网 发布:android 与js交互 编辑:程序博客网 时间:2024/05/18 07:54
rich-text是一个新增的微信小程序插件,从基础库1.4.0开始,低版本需要做兼容处理
nodes属性可为Array和String类型,但推荐使用Array.由于String类型最终也会转为Array类型
nodes分为支持两种节点,分别为元素节点(type=node ,默认为元素节点)和文本节点(type=text)
元素节点
name 标签名 String 是 支持部分受信任的HTML节点attrs 属性 Object 否 支持部分受信任的属性,遵循Pascal命名法children 子节点列表 Array 否 结构和nodes一致
<!-- rich-text.wxml --><rich-text nodes="{{nodes}}" bindtap="tap"></rich-text><!--{{nodes}}其中的变量名与data中名字相同--><!--支持默认事件tap、touchstart、touchmove、touchcancel、touchend和longtap-->
// rich-text.jsPage({ data: { nodes: [{ name: 'div', attrs: { class: 'div_class', style: 'width : 100px; height : 100px; color: red;' }, children: [{ type: 'text', text: 'Hello World!' }] }] }, tap() { console.log('tap') }})
如果页面中存在多个富文本,富文本中存在多个孩子,请看下例:
<!-- rich-text.wxml --><rich-text nodes="{{nodes}}"></rich-text><rich-text nodes="{{nodes1}}"></rich-text>
// rich-text.jsPage({ data: { nodes: [{ name: 'div', attrs: { class: 'div_class', style: 'width : 100px; height : 100px; color: red;' }, children: [{ type: 'text', text: 'Hello World!' }] }], nodes1: [{ name: 'p', attrs: { class: 'p_class', style: 'text-align : center; color: green;' }, children: [{ type: 'text', text: '我是p标签!!!' },{ name: "span", attrs: { style: "color:red", class: "span_class" }, children: [{ type: "text", text: '我是span标签,哈哈哈哈' }] }] }] },})
文本节点
text 文本 String 是 支持entities
<!-- rich-text.wxml --><rich-text nodes="{{nodes}}"></rich-text>
// rich-text.jsPage({ data: { nodes: "我是文本节点,意外不?" },})
注意:
- 全局支持class和style属性,不支持id属性。
- nodes 不推荐使用 String 类型,性能会有所下降
- rich-text 组件内屏蔽所有节点的事件。
- name 属性大小写不敏感
- 如果使用了不受信任的HTML节点,该节点及其所有子节点将会被移除,受信任的html节点请看官方文档
- img 标签仅支持网络图片
阅读全文
2 0
- [微信小程序] rich-text富文本
- Rich Text Processing富文本处理
- 微信小程序 rich-text
- 纯HTML5+CSS实现富文本(Rich Text Format)输入
- 微信小程序 rich-text a标签
- 微信小程序----组件之rich-text
- Rich Text Editing : Sample Project(富文本编辑)
- Rich Text Edit for ios(富文本编辑)
- Text使用富文本
- 微信小程序富文本解析
- RTF(rich textformat)富文本格式
- RTF(rich textformat)富文本格式
- RTF(rich textformat)富文本格式
- RTF(rich textformat)富文本格式
- 用TextView实现Rich Text(富文本编辑器)---在同一个TextView中设置不同的字体风格
- 微信小程序富文本组件wxParse
- 微信小程序之HTML富文本解析
- 微信小程序中使用富文本
- MySql enum字段使用问题
- hihocoder第九十六周 数论五·欧拉函数
- shell脚本中字符串截取的方法
- Json的使用
- 数据结构之哈夫曼树、红黑树
- [微信小程序] rich-text富文本
- 自定义view画一个圆点击可以拖动
- (转)Qt Model/View 学习笔记 (一)——Qt Model/View模式简介
- hibernate相关配置(较全)
- java 从网络Url中下载文件
- [Err] 1293
- iOS 获取当前日期是星期几
- 图像处理学习笔记(四):多边形检测
- 使用visualvm工具进行tomcat性能调优和性能监控