使用微信小程序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就好了
正确代码示例: