Giter VIP home page Giter VIP logo

weparser's Introduction

weParser - 微信小程序富文本解析插件

使用方法

  • 将 weParser 组件完整引入小程序项目
- weParser/
  - html2json.js
  - htmldiscode.js
  - htmlparser.js
  - weparser.wxml
  - weparser.wxss
  • 文件引入

js 文件

// 在使用的页面 js 中引入 weParser 模块
import WeParser from '../../weParser/weparser.js';

// 使用 WeParser 处理 HTML 数据,然后返回给模板文件
let data = WeParser('html', data.content);

wxml 文件

<!-- 在对应页面的 wxml 文件中引入 weParser 模块 -->
<import src="../../weParser/weparser.wxml"/>

<!-- 在需要渲染 HTML 数据的地方,使用模板渲染 -->
<template is="weParser" data="{{ weParserData: data }}"/>

wxss 文件

/* 在 app.wxss 中引入默认的样式文件 */
@import "/weParser/weparser.wxss";

当然,有时需要处理的数据不是单一的对象,而是一个数组里的数据,此时需要遍历并处理。

let data = res.map((item, index, array) => {
  item.content = WeParser('html', item.content);
  return item;
});

这样将 res 中每个对象的 content 属性使用 weParser 单独处理,再返回数据即可。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.