- wxml-to-canvas,模拟器环境下,创建 image 画布报错。
使用官方提供的 demo,wxml-to-canvas 包的引用路径做了私有化处理。 // 引用 wxml-to-canvas "usingComponents": { "wxml-to-canvas": "../../wxcomponents/wxml-to-canvas/src/index" } 私有化包 wxml-to-canvas 和 widget-ui [图片] 修改 wxml-to-canvas 中对 widget-ui 的引用路径 //widget.js 中 const Block = require('../../widget-ui/dist/index.js') 使用官方提供的 demo export const wxmlTempl = ()=>{ return ` <view class="container" > <view class="item-box red"> </view> <view class="item-box green" > <text class="text">yeah!</text> </view> <view class="item-box blue"> <image class="img" src="https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3582589792,4046843010&fm=26&gp=0.jpg"></image> </view> </view> ` } export const styleTempl = { container: { width: 300, height: 200, flexDirection: 'row', justifyContent: 'space-around', backgroundColor: '#ccc', alignItems: 'center', }, itemBox: { width: 80, height: 60, }, red: { backgroundColor: '#ff0000' }, green: { backgroundColor: '#00ff00' }, blue: { backgroundColor: '#0000ff' }, text: { width: 80, height: 60, textAlign: 'center', verticalAlign: 'middle', } } <wxml-to-canvas ref="drawImageRef" width="375" height="550" class="widget" ></wxml-to-canvas> const toShareWx = async () => { const imgContainer = await drawImageRef.value.renderToCanvas({wxml: wxmlTempl(), style: styleTempl}); const imgRes = await drawImageRef.value.canvasToTempFilePath(); } 报错:draw.js const _drawImage = (img) => { if (this.use2dCanvas) { console.log('canvas:', canvas); const Image = canvas.createImage() // 这行报错 Image.onload = () => { ctx.drawImage(Image, x, y, w, h) ctx.restore() resolve() } Image.onerror = () => { reject(new Error(`createImage fail: ${img}`)) } Image.src = img } else { ctx.drawImage(img, x, y, w, h) ctx.restore() resolve() } [图片]
2023-06-09 - onReachBottom开发者工具(v1.01.1711300)上只能触发一次
[代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"reciter-container container"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"tab-bar"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"tab-bar-left"[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]bindtap[代码][代码]=[代码][代码]"switchTab"[代码] [代码]data-index[代码][代码]=[代码][代码]"{{item.index}}"[代码] [代码]class[代码][代码]=[代码][代码]"{{(tab.current == item.index) ? 'tab-bar-item-current' : ''}} tab-bar-item"[代码] [代码]wx:for-items[代码][代码]=[代码][代码]"{{tabs}}"[代码] [代码]wx:key[代码][代码]=[代码][代码]"{{index}}"[代码][代码]>[代码][代码] [代码][代码]{{item.display}}[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"tab-bar-query"[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"reciter-content"[代码] [代码]scroll-y[代码][代码]=[代码][代码]"{{true}}"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"reciter-content-main"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]style[代码][代码]=[代码][代码]"width: 100px;"[代码] [代码]wx:for-items[代码][代码]=[代码][代码]"{{reciterList}}"[代码] [代码]wx:key[代码][代码]=[代码][代码]"{{index}}"[代码][代码]>{{item.name}}</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码]</[代码][代码]view[代码][代码]>[代码][代码]Page({[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]tabs: [{index: 0, display: [代码][代码]'朗诵'[代码][代码]}, {index: 1, display: [代码][代码]'诗词'[代码][代码]}, {index: 2, display: [代码][代码]'比赛'[代码][代码]}],[代码][代码] [代码][代码]tab: {[代码][代码] [代码][代码]current: 0[代码][代码] [代码][代码]},[代码][代码] [代码][代码]reciterList: [],[代码][代码] [代码][代码]},[代码][代码] [代码][代码]onPullDownRefresh: [代码][代码]function[代码][代码]() {[代码][代码] [代码][代码]console.log([代码][代码]'onPullDownRefresh'[代码][代码]);[代码][代码] [代码][代码]wx.showNavigationBarLoading();[代码][代码] [代码][代码]setTimeout(() => {wx.stopPullDownRefresh(); console.log([代码][代码]'stopPullDownRefresh'[代码][代码]); wx.hideNavigationBarLoading()}, 3000)[代码][代码] [代码][代码]},[代码][代码] [代码][代码]onReachBottom: [代码][代码]function[代码][代码]() {[代码][代码] [代码][代码]console.log([代码][代码]'onReachBottom'[代码][代码]);[代码][代码] [代码][代码]this[代码][代码].setData({reciterList: [代码][代码]this[代码][代码].data.reciterList.concat([{name: [代码][代码]'a'[代码][代码]}])});[代码][代码] [代码][代码]},[代码][代码] [代码][代码]onShow: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]console.log([代码][代码]'onShow'[代码][代码]);[代码][代码] [代码][代码]},[代码][代码] [代码][代码]switchTab: [代码][代码]function[代码][代码](e) {[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]tab: {[代码][代码] [代码][代码]current: e.currentTarget.dataset.index[代码][代码] [代码][代码]}[代码][代码] [代码][代码]});[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fetchData: [代码][代码]function[代码][代码]() {[代码] [代码] [代码][代码]}[代码][代码]})[代码][代码]{[代码][代码] [代码][代码]"usingComponents"[代码][代码]: {[代码][代码] [代码][代码]"list-item"[代码][代码]: [代码][代码]"../components/list_item/index"[代码][代码] [代码][代码]},[代码][代码] [代码][代码]"enablePullDownRefresh"[代码][代码]: [代码][代码]true[代码][代码],[代码][代码] [代码][代码]"onReachBottomDistance"[代码][代码]: 50[代码][代码]}[代码] 事件在开发者工具和手机上都只能触发一次,正常么?如何触发多次?
2017-12-04