小猪猪 2019-06-29
export function getRequest(url, data) {
var getRequest = wxPromisify(wx.request)
return getRequest({
url: url,
method: 'GET',
data: data,
header: {
'Content-Type': 'application/json'
}
})
}然后再页面就可以调用后台接口了,
wxRequest.getRequest("http://localhost:8763/permiBlog/getAllBlog",params).then(res=>{
console.log(res.data.code);
if(res!=null && res.data.code=='0'){
for(var i=0;i<res.data.data.content.length;i++){
this.articleList.push(res.data.data.content[i]);
}
}
});需要注意的是,小程序调用后台接口,是要用域名并且是https协议来调用,本地调试的时候,要设置为不校验合法域名
"enablePullDownRefresh": true
然后再首页实现两个方法
// 上拉加载
onReachBottom: function () {
//执行上拉执行的功能
this.getArticleList(this.page+1,5);
},
// 停止下拉刷新
async onPullDownRefresh() {
// to doing..
// 停止下拉刷新
wx.stopPullDownRefresh();
},这样小程序首页就完成了。