在onLoad(options)中,如下错误,求解
发布于 5 年前 作者 vcai 19030 次浏览 来自 问答

thirdScriptError

Cannot read property ‘inviteCode’ of undefined;at pages/index/index page lifeCycleMethod onLoad function

TypeError: Cannot read property ‘inviteCode’ of undefined

    at t.onLoad (http://127.0.0.1:61317/appservice/pages/index/index.js:682:18)

    at t.<anonymous> (http://127.0.0.1:61317/appservice/__dev__/WAService.js:18:21400)

    at t.onShow (http://127.0.0.1:61317/appservice/pages/index/index.js:901:10)

    at t.<anonymous> (http://127.0.0.1:61317/appservice/__dev__/WAService.js:18:21400)

    at Kt (http://127.0.0.1:61317/appservice/__dev__/WAService.js:19:5408)

    at en (http://127.0.0.1:61317/appservice/__dev__/WAService.js:19:7211)

    at nn (http://127.0.0.1:61317/appservice/__dev__/WAService.js:19:7549)

    at Function.<anonymous> (http://127.0.0.1:61317/appservice/__dev__/WAService.js:19:9990)

    at X.<anonymous> (http://127.0.0.1:61317/appservice/__dev__/WAService.js:18:9835)

    at X.emit (http://127.0.0.1:61317/appservice/__dev__/WAService.js:7:31757)

报错代码为:

onLoad: function (options) {

var page = this;

//分享获取参数“邀请码”,存为全局变量

// console.log(app.globalData.inviteCode +"-1-1号")

// console.log(options.inviteCode +"-1-2号")

if (app.globalData.inviteCode == ‘’ || app.globalData.inviteCode==undefined){

// console.log(options.inviteCode +"-1-3号")

if (options.inviteCode != ‘’ && options.inviteCode != undefined) {   //读到这一行就报错

app.globalData.inviteCode = options.inviteCode;

}

console.log(app.globalData.inviteCode +"-1-4号")

}

},

2 回复

optionsapp.globalData有一个为undefined,看下你的app.js?还有你的onShow?

我在跳转到当前页面前,是传了参数的,有没有办法屏蔽这种错误

回到顶部