小程序的后台数据 前端加载时页面展示

onLoad: function (options) {
// var secondId = options.id;
var that = this;
wx.request({
url: 'http://gank.io/api/xiandu/categories',
method: "get",
header: {
'content-type': 'application/json' // 默认值
},
success: function (res) {
console.log(res.data.results);
that.setData({
zhihu: res.data.results
//res代表success函数的事件对,data是固定的,stories是是上面json数据中stories
})
},
fail:function(res){
console.log(2)
}
})
}
 
 
结构
<block wx:for="{{zhihu}}">
<text style='display:block'>{{item.name}}</text>
</block>

猜你喜欢

转载自www.cnblogs.com/liuliang389897172/p/9247251.html