//js 文件
var canvas = {
ctx: null,
createCtx: function () {
this.ctx = wx.createCanvasContext('tab_canvas')
},
initCanvas: function (point, widht, showItem) {
console.log("initCanvas", this.ctx)
if (!this.ctx) {
this.createCtx();
}
...
}
}
module.exports = canvas
//pages 文件
var canvas = require('../../../utils/canvas2.js')
Page({
onLoad: function (options) {
...
canvas.initCanvas(array, that.data.canvasW)
}
})
-----------------------------------END--------------------------------
console.log("initCanvas", this.ctx)
这句日志的输出 第一次进入页面 为null 退出页面 再进去后竟然有值了