相同的地方为什么this指定的不一样呢

onLoad: function (options) {

      var that = this

        wx.request({

            url: 'http://127.0.0.1:8889/api/club/userlist',

            data:{

                clubnumber:app.globalData.myclub

            },

            method:'post',

            header:{

                'content-type':'application/json'

            },

            success:function(res){

                that.setData({

                    userinfo:res.data

                })

            }

        })

  }



onLoad: function (options) {

        wx.request({

            url: 'http://127.0.0.1:8889/api/club/finded',

            data:{

                name:app.globalData.findClub,

                number:app.globalData.findNumber

            },

            header:{

                'content-type':'application/json'

            },

            method:'post',

            success:(res)=>{

                const {name,clubclass,admin,member} = res.data

                this.setData({

                    name:name,

                    clubclass:clubclass,

                    admin:admin,

                    member:member

                })

            }

        })

  }


以上俩都是在监听页面加载的时候的函数,但是一个不用重定向this,一个需要定向this,不然就会报错,为什么会出现这种情况呢


第一段函数是一个子页面 是要tabbar点进去的页面 难道是因为这个原因吗 求大佬解答啊~


潇潇雨雨
浏览 394回答 5
5回答

白板的微信

没看到第二个是箭头函数吗 0.0

慕的地6264312

因为调用的地方不一样吧

鸿蒙传说

箭头函数继承的是上下文的作用域,而非箭头函数继承的执行该函数的作用域

湖上湖

你第一个是非箭头函数所以没改变this的作用域,第二个用到了箭头函数改变了this的作用域。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript