微信小程序Cannot read property 'setData' of null;

使用微信小程序API进行从本地相册选择图片或使用相机拍照功能时出现错误

VM2653:1 thirdScriptError
Cannot read property 'setData' of null;at pages/other/yeji/yeji clickImg function;at api chooseImage success callback function
TypeError: Cannot read property 'setData' of null
    at success (http://127.0.0.1:17830/appservice/pages/other/yeji/yeji.js:60:13)
    at Function.function.u.(anonymous function) (http://127.0.0.1:17830/appservice/__dev__/WAService.js:4:17960)
    at Object.success (http://127.0.0.1:17830/appservice/__dev__/WAService.js:3:27202)
    at u (http://127.0.0.1:17830/appservice/__dev__/WAService.js:5:2741)
    at Function.<anonymous> (http://127.0.0.1:17830/appservice/__dev__/WAService.js:5:2919)
    at n.function.setTimeout (http://127.0.0.1:17830/appservice/appservice?t=1536637119574:1478:7798)
    at http://127.0.0.1:17830/appservice/__dev__/WAService.js:3:27202
    at http://127.0.0.1:17830/appservice/__dev__/WAService.js:3:23570

错误的使用示例:

错误示例

错误原因:this在方法里面代表的是这个choseImage方法 而不是page对象,所以在外部定义一下this就好了

正确代码示例:

 

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页