微信小程序开发者微信小程序开发小程序

微信小程序解析html,wxParse的使用

2019-11-18  本文已影响0人  独西楼Q

项目中有显示后台传过来富文本前端显示的功能,因为微信小程序没有html语法,用了wxParse组件解析HTML

wxParse githubd地址: https://github.com/icindy/wxParsewxParse的源文件和使用方法

image.png
如果用rich-text,结果就是这样
image.png

前端显示:


image.png

wxParse的应用

1.拷贝 wxParse 文件夹,放在项目文件夹下

image.png

2.引用 wxParse

//在使用的Wxss中引入WxParse.css,可以在app.wxss
@import "/wxParse/wxParse.wxss";
//在使用的js中引入WxParse模块
const WxParse = require('../../wxParse/wxParse.js');
// 在使用的wxml引入模板
<import src="你的路径/wxParse/wxParse.wxml"/>
//这里data中article为bindName
<template is="wxParse" data="{{wxParseData:article.nodes}}"/>

3.数据绑定

var article = '<div>我是HTML代码</div>';

var that = this;
WxParse.wxParse('article', 'html', article, that, 5);
上一篇 下一篇

猜你喜欢

热点阅读