这一步很关键,在微信开发者工具左上角-》工具-》npm构建。 PS:我第一次用的时候就忘了我构建了
支持 view、text、image 三种标签,通过 class 匹配 style 对象中的样式。 注意:需为每个元素指定 width 和 height 属性,否则会导致布局错误。 元素均为 flex 布局。left/top 等 仅在 absolute 定位下生效。
1.首先下载引入官方demo,然后在node_modules/wxml-to-canvas/miniprogram_dist/index.js 里边,找到并复制如下代码:
async drawImage(img, box, style) { await new Promise((resolve, reject) => { const ctx = this.ctx const canvas = this.canvas const { borderRadius = 0 } = style const { left: x, top: y, width: w, height: h } = box ctx.save() this.roundRect(x, y, w, h, borderRadius, false, false) ctx.clip() const Image = canvas.createImage() Image.onload = () => { ctx.drawImage(Image, x, y, w, h) ctx.restore() resolve() } Image.onerror = () => { reject() } Image.src = img }) }复制后找到 自己项目所对应的node_modules/wxml-to-canvas/miniprogram_dist/index.js中,粘贴(覆盖)原来所对应的代码即可。