Page({
data: {
logs: ''
},
onLoad: function () {
let that = this;
wx.request({
url: 'https://m.jd.com/index/recommend.action?_format_=json&page=1',//自己模拟的接口地址
method: "GET",
header: {
"Content-Type": "application/json"
},
success: function (res) {
const datas = JSON.parse(res.data.recommend)
//如果用 that.data.logs = datas 直接赋值时数据不会渲染到页面上,必须用this.setData({})才可行
//还需要注意在上边把this再赋一个变量,否则this会改变
that.setData({
logs: datas.wareInfoList
})
},
fail: function (err) { },//请求失败
complete: function () { }
})
}
})