Convert WeChat Mini Program Pages to Images

Recently, I encountered a requirement in a project, that is, to convert a certain page into an image and then pass it to the backend. I searched carefully and found that the official Api, which is the image generated by wx.canvasToTempFilePath, is likely to be empty, too I was stuck, so I gave up using it and chose to use wxml2canvas.

Install wxml2canvas

npm init
npm install wxml2canvas --save --production

npm init is npm initialization. At this time, according to the compiler terminal all the way, a package.json file will eventually be generated
– production is to reduce the installation of packages that are not related to business and reduce the size of the project. If you don’t build npm, you need our tool-build npm, or check it.
insert image description here
If you don’t see this item, don’t worry, our advanced version of WeChat Developer Tools supports npm by default, and it is built by default. Then we need to create a new index.js under the utils folder. The function of this file is to convert the page into an image. The code is as follows:

//此js文件主要用于将页面转图片

import Util from 

Guess you like

Origin blog.csdn.net/qq_37635012/article/details/129334589