編寫后台服務接口配置文件
const basePath = 'http://test.cdbhbc.com/wbgapi';
const urlList = {
refreshTokeUrl: basePath + '/refreshToke',
loginUrl: basePath + '/wxappLogin',
advertPicListUrl: basePath + '/advertPicList',
shopSortListUrl: basePath + '/shopSortList',
shopListUrl: basePath + '/shopList',
shopDetailUrl: basePath + '/shopDetail',
goodsSortListUrl: basePath + '/goodsSortList',
goodsListUrl: basePath + '/goodsList',
goodsDetailUrl: basePath + '/goodsDetail',
orderListUrl: basePath + '/orderList',
orderDetailUrl: basePath + '/orderDetail',
payBeforeInfoUrl: basePath + '/payBeforeInfo',
submitOrderUrl: basePath + '/submitOrder',
emptyShopCartUrl: basePath + '/emptyShopCart',
addShopCartUrl: basePath + '/addShopCart',
shopCartListUrl: basePath + '/shopCartList',
shopCartBuyCountOperateUrl: basePath + '/shopCartBuyCountOperate',
wxPayUrl: basePath + '/wxPay/payConfig',
goodsSpecialDetailUrl: basePath + '/goodsSpecialDetail',
submitSpecialOrderUrl: basePath + '/submitSpecialOrder',
shopMyListUrl: basePath + '/shopMyList',
shopMyAddUrl: basePath + '/shopMyAdd',
}
module.exports = urlList;
接口配置文件的使用
const urlList = require('../../utils/config.js');
App({
refreshToke(){
wx.login({
success: res => {
if(res.errMsg == 'login:ok'){
wx.request({
url: urlList.refreshTokeUrl,
data: { code: res.code },
success: res => {
if(res.data.state == 'true'){
wx.setStorageSync('token', res.data.data.token);
this.globalData.token = res.data.data.token;
}
}
})
}
}
})
}
})
接口配置文件的作用
- 在項目開發時能夠在固定位置很快查到需要的接口;
- 服務器地址改變時,只用替換 basePath 的值,就能全部替換,不用去單獨頁面替換;
- 方便接口的集中管理,方便后期的維護。
DEMO下載
我的博客,歡迎交流!
我的CSDN博客,歡迎交流!
微信小程序專欄
前端筆記專欄
微信小程序實現部分高德地圖功能的DEMO下載
微信小程序實現MUI的部分效果的DEMO下載
微信小程序實現MUI的GIT項目地址
微信小程序實例列表
前端筆記列表
游戲列表