获取组件时并调用组件功能时有时报空指针?
发布于 7 年前 作者 jzeng 8944 次浏览 来自 官方Issues

这个是调用组件的代码:

isTimeout: function( ){

let that = this;

console.log(“超时调用”);

this.setData({

isTimeout: false,

cliCode: ‘1’,

imgvCode: false,

imgTime: app.$UTIL.generateSignTime2()+this.data.imgTimeLimit,

})

this.selectComponent(’#use’).onTap();

}

下面是组件的代码:

// my-component/random-code.js

var Mcaptcha = require(’…/…/utils/mcaptcha.js’);

var $MSG = require(’…/…/utils/msg.js’);

Component({

/**

  * 组件的属性列表

  */

properties: {

},

/**

  * 组件的初始数据

  */

data: {

text: ‘’,

},

/**

  * 组件的方法列表

  */

methods: {

//刷新验证码

onTap() {

this.mcaptcha.refresh();

},

validate(imgCode) {

var res = this.mcaptcha.validate(imgCode);

if (imgCode == ‘’ || imgCode == null ) {

wx.showModal({

content: $MSG.IMG_CODE_NULL,

showCancel:false

})

return false;

}

if (!res) {

// wx.showModal({

//   content:‘图形验证码有误’,

//   showCancel: false

// })

return false;

}

return true;

}

},

ready: function() {

var that = this

this.mcaptcha = new Mcaptcha({

el: ‘canvas’,

width: 80,

height: 35,

createCodeImg: “”,

target: that

});

}

})

偶尔在this.mcaptcha.refresh();  报

Cannot read property ‘onTap’ of null; [Component] Event Listener Error @ my-component/verify-code/verify-code#(anonymous) TypeError: Cannot read property ‘onTap’ of null at _e.isTimeout (https://pages/index/index.js:1053:26)

错误

回到顶部