美文网首页
html转码wxml

html转码wxml

作者: 子语喵 | 来源:发表于2019-05-23 16:47 被阅读0次

1.到https://github.com/icindy/wxParse下载
2.在我们需要的js里面引入wxParse模块

import WxParse from '../../wxParse/wxParse.js';

3.在使用的wxss里面引入wxParse.wxss。当然也可以在全局的wxss里面引用

@import "/wxParse/wxParse.wxss";

4.数据获取到之后进行绑定

/**
* WxParse.wxParse(bindName , type, data, target,imagePadding)
* 1.bindName绑定的数据名(必填)
* 2.type可以为html或者md(必填)
* 3.data为传入的具体数据(必填)
* 4.target为Page对象,一般为this(必填)
* 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选)
*/

var article = res.data.content;//article是取到的数据
WxParse.wxParse('article', 'html', article, that, 5);

5.wxml中也要引用模板

<import src="../../wxParse/wxParse.wxml"/>
<template is="wxParse" data="{{wxParseData:article.nodes}}"/>

6.最后就是这样啦!


image.png

相关文章

网友评论

      本文标题:html转码wxml

      本文链接:https://www.haomeiwen.com/subject/disbzqtx.html