wx.request里面是不是不能调用封装的函数啊

发布于 6 年前作者 ping534964 次浏览最后编辑 6 年前来自 ask

大佬们帮我看看

在其他的地方都可以调用getData()

在这里就不行了

3 回复
linxiuying
linxiuying1 楼6 年前

哦哦好的 我试一下

yang29
yang292 楼6 年前

把this定义到外部,你这里的this指向已发生变化

qdai
qdai3 楼4 年前

此时的 this 指向的是 wx.request success 回调函数的 this,不是 Page 的 this。只有 Page 的 this 上才有你的 getData。应该在这里获取 this。

chongxinhuoqu: function () {
 var that = this;
}

建议去看一些讲解 JS 中 this 的文章。