Skip to content

Commit

Permalink
fix(taro-components): fix richText component (#2131)
Browse files Browse the repository at this point in the history
主要修改了两个地方:
1. RichText这个组件,nodes的type如果不是text的话,children这个属性在微信小程序的doc里是可选的,所以item.children就可能为undefined,所以加个默认值空数组。
2. 对于有些node类型,例如image,它的attrs不仅仅限于class和style,还有src、width、height等。由于情况比较多,所以这块建议直接把这些属性拿过来,统统赋给props
  • Loading branch information
pamler authored and luckyadam committed Feb 14, 2019
1 parent 7f52af0 commit dd6c722
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/taro-components/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ class RichText extends Nerv.Component {
style: ''
}
if (item.hasOwnProperty('attrs')) {
obj.className = item.attrs.class || ''
obj.style = item.attrs.style || ''
for (const key in item.attrs) {
if (key === 'class') {
obj.className = item.attrs[key] || ''
} else {
obj[key] = item.attrs[key] || ''
}
}
}
return Nerv.createElement(item.name, obj, child)
}
}

renderChildrens (arr) {
renderChildrens (arr = []) {
if (arr.length === 0) return
return arr.map((list, i) => {
if (list.type === 'text') {
Expand Down

0 comments on commit dd6c722

Please sign in to comment.