[微信小程序] rich-text富文本
2017-08-03 09:46
155 查看
rich-text是一个新增的微信小程序插件,从基础库1.4.0开始,低版本需要做兼容处理
nodes属性可为Array和String类型,但推荐使用Array.由于String类型最终也会转为Array类型
nodes分为支持两种节点,分别为元素节点(type=node ,默认为元素节点)和文本节点(type=text)
元素节点
如果页面中存在多个富文本,富文本中存在多个孩子,请看下例:
文本节点
注意:
全局支持class和style属性,不支持id属性。
nodes 不推荐使用 String 类型,性能会有所下降
rich-text 组件内屏蔽所有节点的事件。
name 属性大小写不敏感
如果使用了不受信任的HTML节点,该节点及其所有子节点将会被移除,受信任的html节点请看官方文档
img 标签仅支持网络图片
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.js Page({ 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.js Page({ 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标签!!!' },{ na b2a3 me: "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.js Page({ data: { nodes: "我是文本节点,意外不?" }, })
注意:
全局支持class和style属性,不支持id属性。
nodes 不推荐使用 String 类型,性能会有所下降
rich-text 组件内屏蔽所有节点的事件。
name 属性大小写不敏感
如果使用了不受信任的HTML节点,该节点及其所有子节点将会被移除,受信任的html节点请看官方文档
img 标签仅支持网络图片
相关文章推荐
- 微信小程序----组件之rich-text
- 微信小程序 rich-text
- 微信小程序 rich-text的使用方法
- 「微信小程序免费辅导教程」26,基础内容组件rich-text体验
- 微信小程序 rich-text a标签
- 微信小程序传参数的几种方法
- 微信小程序 多页面
- 简单微信小程序的体验
- 微信小程序--搜索电影app(续)
- 微信小程序用户数据解密
- 微信小程序promsie.all和promise顺序执行
- 一名Android开发者的微信小程序填坑之路
- 微信小程序 页面跳转及数据传递详解
- Android中微信小程序开发之弹出菜单
- 微信小程序 如何获取时间
- 微信小程序开发 ---3
- 微信小程序开发之『顶部导航』特效
- 微信小程序使用audio组件播放音乐功能示例【附源码下载】
- 微信小程序自学第三课:文件作用域,模块化