微信开发者工具更新之后代码报错
发布于 6 年前 作者 xiasong 12289 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

对应代码:wx.cloud.callFunction({

          name: ‘login’,

          data: {},

          success: function success(res) {

            console.log(’[云函数] [login] user openid: ', res.result.openid);

            app.globalData.openid = res.result.openid;

报错信息

thirdScriptError

Cannot set property ‘openid’ of undefined;at api cloud.callFunction success callback function

TypeError: Cannot set property ‘openid’ of undefined

    at Function.success

  • 预期表现

app.globalData.openid获取到res.result.openid的值,正常执行,无报错异常

  • 复现路径

预览和真机调试都正常,升级开发工具v1.02.1901230报错,上一版本v1.02.1812271正常

  • 提供一个最简复现 Demo

wx.cloud.callFunction({

          name: ‘login’,

          data: {},

          success: function success(res) {

            console.log(’[云函数] [login] user openid: ', res.result.openid);

            app.globalData.openid = res.result.openid;

          },

          fail: function fail(err) {

            console.error(’[云函数] [login] 调用失败’, err);

            wx.navigateTo({

              url: ‘…/deployFunctions/deployFunctions’

            });

          }

        });

1 回复

原因找到了!

如下的代码只能存在于app.js中,我在另一个页面中也出现了App({,从别处拷贝的,虽然没用到。可能是上一个版本开发工具编译的规则没有检测到,这个版本更加严格检测到了的原因

App({

})

参考:https://q.cnblogs.com/q/106003

启发来自这句:

注意:

App() 必须在 app.js 中注册,且不能注册多个。

回到顶部