【微信小程序开发遇到的那些坑】之——TypeError: r.complete is not a function

我遇到这个错真的找不出来,不知道为什么错,也没有报第几行第几列。

我承认是我js基础太薄弱,没怎么实战就上手小程序,记录一下自己经历的坑吧。。

希望对看到这篇文章的你能有所帮助~


首先我的page的data(页面初始数据)是这样写的:

data: {
    user: {
      username: app.globalData.username,
      userid: app.globalData.userid,
      userphoto: app.globalData.userphoto
    }
  },

我在之后读取缓存数据,并且试图将缓存数据存入data,错误写法:

onShow: function() {
    var that = this;
    var username = 'user.username';
    var userphoto = 'user.userphoto';
    var userid = 'user.userid';
    //读取账号缓存
    wx.getStorage({
      key: 'userInfo',
      success: function(res) {

        //输出缓存中的数据:
        console.log("缓存中的数据:");
        console.log(res.data);

        //更改页面中的值
        that.setData({
          [username]: res.data.username
        },{
          [userphoto]: res.data.userphoto,
        },{
          [userid]: res.data.userid
        });
        
        //输出该页面的data
        console.log("页面的data");
        console.log(that.data);
      }
    });

正确写法:

onShow: function() {
    var that = this;
    var username = 'user.username';
    var userphoto = 'user.userphoto';
    var userid = 'user.userid';
    //读取账号缓存
    wx.getStorage({
      key: 'userInfo',
      success: function(res) {

        //输出缓存中的数据:
        console.log("缓存中的数据:");
        console.log(res.data);

        //更改页面中的值
        that.setData({
          [username]: res.data.username,
          [userphoto]: res.data.userphoto,
          [userid]: res.data.userid
        });
        
        //输出该页面的data
        console.log("页面的data");
        console.log(that.data);
      }
    });

写这个bug是在我上手小程序1,2天这样子,在我今天调试的时候报错,我根本找不见呀哭唧唧,所以这个r.complete is not a function应该是指这种类似的问题。

last but not least!

一定要多打印日志!!多console.log!!!!


谢谢你看到这里!写作仓促,有疏漏之处还请评论指正,共同探讨进步!


猜你喜欢

转载自blog.csdn.net/LimonSea/article/details/81712737
今日推荐