html代码在小程序上显示
发布于 2 年前 作者 vfu 3265 次浏览 来自 分享

wxParse-微信小程序富文本解析组件,可以解析富文本为小程序可以显示的内容

支持

基本使用方法

  1. Copy文件夹wxParse
- wxParse/
  -wxParse.js(必须存在)
  -html2json.js(必须存在)
  -htmlparser.js(必须存在)
  -showdown.js(必须存在)
  -wxDiscode.js(必须存在)
  -wxParse.wxml(必须存在)
  -wxParse.wxss(必须存在)
  -emojis(可选)
  1. 在你要使用的页面中引用
//在使用的View中引入WxParse模块
var WxParse = require('../../wxParse/wxParse.js');
//在使用的Wxss中引入WxParse.css,可以在app.wxss
[@import](/user/import) "/wxParse/wxParse.wxss";
  1. 数据绑定
 var article = '<div>我是HTML代码</div>';
/**
* WxParse.wxParse(bindName , type, data, target,imagePadding)
* 1.bindName绑定的数据名(必填)
* 2.type可以为html或者md(必填)
* 3.data为传入的具体数据(必填)
* 4.target为Page对象,一般为this(必填)
* 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选)
*/
var that = this;
WxParse.wxParse('article', 'html', article, that, 5);
  1. 模板引入
<import src="你的路径/wxParse/wxParse.wxml"/>
<template is="wxParse" data="{{wxParseData:article.nodes}}"/>

更多

更多使用及二次开发可以查看官方仓库wxParse

3 回复

简单的使用也一用 <rich-text nodes="{{nodes}}"></rich-text>

https://developers.weixin.qq.com/miniprogram/dev/component/rich-text.html

学会了!

社区大佬真多 我算是学到了

回到顶部