小程序
小游戏
企业微信
微信支付
扫描小程序码分享
为啥我的赋值不能赋值到deat里面去,这是为什么。为呀为什么。咦,咦!
12 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
一会that一会this的 烦死了
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
谢谢你们了(↖(^ω^)↗)
在wx.request的success函数里,this的上下文已经改变了,所以要在外面先定义一个const that = this,把this存起来,在wx.request里用that就行了
按 YJFn 的写法就行了
你们说的,咋个我有点乱呢
onLoad: function (options) {
const that = this
var rs = []; wx.request({ url: ', header: { 'content-type': 'application/json' }, success: function (res) { console.log(res.data.showapi_res_body.pagebean.songlist); rs = res.data.showapi_res_body.pagebean.songlist; that.setsj(rs); } }); }, setsj: function (shuju) { console.log(shuju); this.setData({ recommends: shuju });
每个function的第一行都写上const that=this,然后里面凡是用到this的地方全部改成that,就oK了。
啥子是闭包
你可以帮我打一下吗。小熊猫。,,,非常感谢
onLoad: function (options) { var rs = []; wx.request({ url: ', header: { 'content-type': 'application/json' }, success: function (res) { console.log(res.data.showapi_res_body.pagebean.songlist); rs = res.data.showapi_res_body.pagebean.songlist; this.setsj(rs); } }); }, setsj: function (shuju) { console.log(shuju); this.setData({ recommends: shuju });
闭包
正在加载...
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
一会that一会this的 烦死了
谢谢你们了(↖(^ω^)↗)
在wx.request的success函数里,this的上下文已经改变了,所以要在外面先定义一个const that = this,把this存起来,在wx.request里用that就行了
按 YJFn 的写法就行了
你们说的,咋个我有点乱呢
onLoad: function (options) {
const that = this
var rs = [];
wx.request({
url: ',
header: {
'content-type': 'application/json'
},
success: function (res) {
console.log(res.data.showapi_res_body.pagebean.songlist);
rs = res.data.showapi_res_body.pagebean.songlist;
that.setsj(rs);
}
});
},
setsj: function (shuju) {
console.log(shuju);
this.setData({
recommends: shuju
});
每个function的第一行都写上const that=this,然后里面凡是用到this的地方全部改成that,就oK了。
啥子是闭包
你可以帮我打一下吗。小熊猫。,,,非常感谢
onLoad: function (options) {
var rs = [];
wx.request({
url: ',
header: {
'content-type': 'application/json'
},
success: function (res) {
console.log(res.data.showapi_res_body.pagebean.songlist);
rs = res.data.showapi_res_body.pagebean.songlist;
this.setsj(rs);
}
});
},
setsj: function (shuju) {
console.log(shuju);
this.setData({
recommends: shuju
});
闭包