wxParse 主要是用于富文本解析
准备
wxParse 文件下载
github地址: https://github.com/icindy/wxParse
使用
- 复制wxparse 代码到文件夹
- 新建index.js、index.wxml文件
// index.js
import Fuck from './wxParse'
Component({
properties: {
html: {
type: String,
value: '',
},
},
observers: {
html: function () {
Fuck.wxParse('wxParseData', 'html', this.properties.html, this)
},
},
})
// index.wxml
<import src="./wxParse.wxml" />
<template
is="wxParse"
data="{{wxParseData:wxParseData.nodes}}"
key="{{Math.random()}}"
/>
- 在页面文件新建 index.config.js 引入wxparse组件
export default {
usingComponents: {
wxparse: './wxparse/index', // 书写第三方组件的相对路径
},
}
- 使用
<wxparse html={`<p>模拟html代码</p>`} key={Math.random()} />