


How to display html format content in WeChat mini program (graphic tutorial)
The following article mainly introduces you to the method of displaying html format content in WeChat applet. Friends who need it can refer to it. Let’s take a look together.
Preface
In a recent project, I encountered the need to display news content in the WeChat applet. The news content is read from the server through the interface. The rich text content is in html format. The applet does not support the display of content in html format by default. When we need to display html content, we can use wxParse to achieve it.
Preparation work:
First we download wxParse
github address: https:// github.com/icindy/wxParse
Local download: http://xiazai.jb51.net/201704/yuanma/wxParse-master(jb51.net).rar
wxParse
After downloading, we need to use the wxParse folder in the directory and copy it to our project directory
The following are the specific usage steps
1. In the app.wxss global style file, you need to introduce the wxParse style sheet
@import "/page/wxParse/wxParse.wxss";
2. When you need to load Introduce wxParse
var WxParse = require('../../wxParse/wxParse.js');
3 into the js file corresponding to the page with html content. 3. Set the html content by calling the WxParse.wxParse method.
/** * WxParse.wxParse(bindName , type, data, target,imagePadding) * 1.bindName绑定的数据名(必填) * 2.type可以为html或者md(必填) * 3.data为传入的具体数据(必填) * 4.target为Page对象,一般为this(必填) * 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选) */
Page({ data: { }, onLoad: function () { var that = this; wx.request({ url: '', method: 'POST', data: { 'id':13 }, header: { 'content-type': 'application/json' }, success: function(res) { var article = res.data[0].post; WxParse.wxParse('article', 'html', article, that,5); } }) } })
4. Reference the template in the page
<import src="../../wxParse/wxParse.wxml"/> <template is="wxParse" data="{{wxParseData:article.nodes}}"/>
This way you can embed html content in the WeChat applet
Summary
The above is me I compiled it for everyone, I hope it will be helpful to everyone in the future.
Related articles:
How to implement the three-in-one payment code of QQ, WeChat and Alipay using PHP
PHP implementation APPWeChatPayment case analysis
The above is the detailed content of How to display html format content in WeChat mini program (graphic tutorial). For more information, please follow other related articles on the PHP Chinese website!

HTMLtagsareessentialforwebdevelopmentastheystructureandenhancewebpages.1)Theydefinelayout,semantics,andinteractivity.2)SemantictagsimproveaccessibilityandSEO.3)Properuseoftagscanoptimizeperformanceandensurecross-browsercompatibility.

A consistent HTML encoding style is important because it improves the readability, maintainability and efficiency of the code. 1) Use lowercase tags and attributes, 2) Keep consistent indentation, 3) Select and stick to single or double quotes, 4) Avoid mixing different styles in projects, 5) Use automation tools such as Prettier or ESLint to ensure consistency in styles.

Solution to implement multi-project carousel in Bootstrap4 Implementing multi-project carousel in Bootstrap4 is not an easy task. Although Bootstrap...

How to achieve the effect of mouse scrolling event penetration? When we browse the web, we often encounter some special interaction designs. For example, on deepseek official website, �...

The default playback control style of HTML video cannot be modified directly through CSS. 1. Create custom controls using JavaScript. 2. Beautify these controls through CSS. 3. Consider compatibility, user experience and performance, using libraries such as Video.js or Plyr can simplify the process.

Potential problems with using native select on mobile phones When developing mobile applications, we often encounter the need for selecting boxes. Normally, developers...

What are the disadvantages of using native select on your phone? When developing applications on mobile devices, it is very important to choose the right UI components. Many developers...

Use Three.js and Octree to optimize collision handling of third-person roaming in the room. Use Octree in Three.js to implement third-person roaming in the room and add collisions...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools
