wx.createSelectorQuery() .select( '#myCanvas' ) .fields({ node: true , size: true , }) .exec((res) => { console.log(res[0]) }) |
fields中读取node真机返回错误
Uncaught ( in promise) ReferenceError: NativeGlobal is not defined at n.value ([publib]:1) at n.value ([publib]:1) at t ([publib]:1) at n.value ([publib]:1) at eval ([publib]:1) atnew Promise (<anonymous>) at t ([publib]:1) at eval ([publib]:1) at Array.forEach (<anonymous>) at eval ([publib]:1) |
这是什么原因呢?测试机器 小米8、苹果X
感谢反馈,目前真机调试不支持直接获取 Canvas 的 context,现在可以以预览为准。请期待后续更新。
遇到同样的问题,
电脑端调试可以。
手机端远程调试,即出现问题。
使用手机端测试运行,不开启远程调试。正常。
我使用wepy写的小程序。所以 就贴一个文件吧。
第一个评论上面说不支持,感觉那个就是对的哦。
<!--签名--> <style> @import "./common/lib/weui.wxss"; </style> <template> <canvas type="2d" id="signcanvas" @touchstart="starttouch" @touchmove="touchmove" @touchend="touchend" style="width: 100vw; height: 92vh;"></canvas> <cover-view style="height: 8vh;"> <button @tap="confirmSign" type="primary" class="weui-btn weui-btn_primary">签名确认</button> </cover-view> </template> <script> import wepy from 'wepy' import { connect } from 'wepy-redux'; import { REPLACESIGNIMAGEFILEPATH } from '../store/types'; @connect({}, { replaceSignImage: REPLACESIGNIMAGEFILEPATH }) export default class welcome extends wepy.page{ onLoad (option) { let that = this; // 初始化画布, const query = wx.createSelectorQuery(); query.select('#signcanvas') .fields({ node: true, size: true }) .exec((res) => { const canvas = res[0].node; that.canvas = canvas; const ctx = canvas.getContext('2d'); that.canvasContext = ctx; const dpr = wx.getSystemInfoSync().pixelRatio; canvas.width = res[0].width * dpr; canvas.height = res[0].height * dpr; ctx.scale(dpr, dpr); }); } config = { navigationBarTitleText: '签名' } data = { targetSrc: '', canvasContext: {}, canvas: {} } methods = { starttouch: function (e) { console.log('start', e) this.canvasContext.beginPath(); let touchevent = e.touches[0]; this.canvasContext.moveTo(touchevent.x, touchevent.y); }, touchmove: function(e) { console.log('move', e); let touchevent = e.touches[0]; this.canvasContext.lineTo(touchevent.x, touchevent.y); this.canvasContext.stroke(); }, touchend: function(e) { console.log('end', e); // this.canvasContext.draw(); // this.canvasContext.draw(); }, confirmSign: function(e) { let that = this; wx.canvasToTempFilePath({ canvasId: 'signcanvas', canvas: that.canvas, success: (ctx) => { // 获得图片临时路径,用来保存到本地 console.error('save', ctx); that.methods.replaceSignImage(ctx.tempFilePath); }, fail: (err) => { console.error(err); } }) } } } </script>
你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
微信版本号:7.0.8
机型:小米8 MIUI11.0.3
基础库:2.9.3