编写后台服务接口配置文件
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项目地址
微信小程序实例列表
前端笔记列表
游戏列表