Authored by QC-L

完善网络请求,添加 complete 方法 review by 黄敬囿

... ... @@ -9,11 +9,12 @@ export default class BaseService {
}
}
async GET(params, path) {
async GET(params, options) {
return await GET({
url: this.url,
path: path,
params: params
path: options.path,
params: params,
complete: options.complete
}).then(data => {
return data;
}).catch(error => {
... ...
... ... @@ -14,11 +14,17 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.showLoading({
title: '加载中',
})
let api = new NativeTestService();
this.setData({
api:api
})
this.data.api.getHomePageList({page: 1, limit: 20}).then(data => {
});
// () => {} 为 微信原生请求中的 complete
this.data.api.getHomePageList({page: 1, limit: 20}, () => {
wx.hideLoading();
}).then(data => {
console.log(data);
})
// GET({
... ...
... ... @@ -3,13 +3,16 @@ import BaseService from '../../libs/services/baseService.js';
const UFO_SEARCH_LIST = 'ufo.product.search.list';
export default class NativeTestService extends BaseService {
async getHomePageList(params) {
async getHomePageList(params, complete) {
return await this.GET(
{
...params,
method: UFO_SEARCH_LIST
},
'/resources'
{
path: '/resources',
complete
}
).then((data) => {
return data;
}).catch((error) => {
... ...