微信小程式 rich text富文字

2021-08-04 20:31:09 字數 1211 閱讀 5557

nodes屬性可為array和string型別,但推薦使用array.由於string型別最終也會轉為array型別

nodes分為支援兩種節點,分別為元素節點(type=node ,預設為元素節點)文字節點(type=text)

元素節點

name        標籤名     string   是  支援部分受信任的html節點

attrs 屬性 object 否 支援部分受信任的屬性,遵循pascal命名法

children 子節點列表 array 否 結構和nodes一致

nodes="}"

bindtap="tap">

rich-text>

}其中的變數名與data中名字相同-->

// rich-text.js

page(,

children:

}]},

tap()

})

如果頁面中存在多個富文字,富文字中存在多個孩子,請看下例:

nodes="

}">

rich-text>

nodes="

}">

rich-text>

// rich-text.js

page(,

children:

}],nodes1: [,

children: [,,

children:

}]}]

},})

文字節點

text    文字      string       是      支援entities

nodes="

}">

rich-text>

// rich-text.js

page(,

})

注意:

微信小程式rich text的使用方法

這是html 結構,其中rich text節點中nodes繫結的就是我們的內容 rich text 然後在page裡面定義html這個引數 注意html型別為字串 data 最後在onload裡面獲取後端返回的資料,傳給html,success res res.data.rs.goodcontent...

原生微信小程式使用wxParse解析富文字

1.先在 js 檔案中引入 import wxparse from wxparse wxparse.js 寫相對路徑 2.獲取到 html 字串後隨便賦個值 let str 即為 獲取到的html字串 str為自定義名字 3.使用 wxparse 解碼字串 wxparse.wxparse str h...

微信小程式 富文字解析

把wxparse放在與page同一級目錄 wxparse裡的emojis包是可要可不要的。1 在wxml中 src wxparse wxparse.wxml class wxparse is wxparse data view 2 在wxss中 import wxparse wxparse.wxss...