小程序接口请求数据

//接口数据为 [ ]格式
let that
Page({
/**
* 页面的初始数据
*/
data: {
list: []
},

 

/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
that = this;
that.anquan_list()
},

 

/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
anquan_list() {
let req = {
// 按照接口数据要求填写
}
wx.request({
url: 网址‘,
data: req,
header: {
‘content-type‘: ‘application/json‘ // 默认值
},
method: ‘GET‘,
success: function (res) {
that.setData({
list: res.data.data
})
console.log(res.data.data)// 拿到的数据
// console.log(Object.prototype.toString.call(res.data.data)) //拿到的数据类型
}
})
},
})
 
 
//接口数据为 {}格式     转换为为[{}]这个格式
let that
Page({
/**
* 页面的初始数据
*/
data: {
list: []
},

 

/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
that = this;
that.anquan_list()
},

 

/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {

 

},

 

/**
* 生命周期函数--监听页面显示
*/
onShow: function () {

 

},

 

/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {

 

},

 

/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {

 

},

 

/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {

 

},

 

/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {

 

},

 

/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {

 

},

 

anquan_list() {
let req = {
// 按照接口数据要求填写

 

}
wx.request({
url: 网址‘,
data: req,
header: {
‘content-type‘: ‘application/json‘ // 默认值
},
method: ‘GET‘,
success: function (res) {
var arr = [ ]
arr.push(res.data.data)
that.setData({list:fanhuizhi})
console.log(res.data.data)// 拿到的数据
// console.log(Object.prototype.toString.call(res.data.data)) //拿到的数据类型
}
})
},
})

 

小程序接口请求数据

上一篇:第一个微信小项目


下一篇:Java Swing (JTable详解1)