在封装网络请求时,对于不同的环境要调用接口的baseUrl是不相同的,在小程序中,我是这样设置的:
// request.js
const envVersion = __wxConfig.envVersion;
let baseUrl;
if(envVersion === 'develop'){
baseUrl = 'https://xxx.xxx.cn/;
}else{
baseUrl = 'https://xxx.xxx..com/';
}
我们可以在这里根据当前的环境进行相应接口的调用。
开发版:envVersion: “develop”
体验版:envVersion:“trial”
正式版:envVersion: “release”
同时,我们也可以
console.log(__wxConfig)
打印出结果为:
{
accountInfo:
appId: "xxxxxxxxxxxxx"
icon: "http://wx.qlogo.cn/mmhead/Q3auHgzwzM52opext62OxLevNrx3DsDxXcyZicicNNfDGVzz5gcqLfNQ/0"
nickname: "XXX"
__proto__: Object
appLaunchInfo:
path: "pages/index/index"
query: {}
referrerInfo: {}
scene: 1001
__public: {path: "pages/index/index", query: {…}, scene: 1001, shareTicket: undefined, referrerInfo: {…}}
__proto__: Object
appType: 0
brand: "devtools"
cloud: false
customClose: false
debug: false
entryPagePath: "pages/index/index.html"
env: {USER_DATA_PATH: "http://usr"}
envVersion: "develop"
ext: {}
extAppid: ""
global: {window: {…}}
language: "zh"
mainPlugins: {}
model: "iPhone 6/7/8"
networkTimeout: {request: 60000, uploadFile: 60000, connectSocket: 60000, downloadFile: 60000}
onReady: ƒ (t)
page: {pages/index/index.html: {…}, pages/auth/auth.html: {…}, pages/logs/logs.html: {…}}
pages: (3) ["pages/index/index", "pages/auth/auth", "pages/logs/logs"]
permission: {scope.userLocation: {…}}
pixelRatio: 2
platform: "devtools"
resizable: false
screenHeight: 667
screenWidth: 375
tabBar: {list: Array(0)}
urlCheck: true
useExtendedLib: {}
version: "7.0.4"
widgets: []
workers: ""
wxAppInfo: {maxRequestConcurrent: 10, maxUploadConcurrent: 10, maxDownloadConcurrent: 10, maxWorkerConcurrent: 1}
__readyHandler: ƒ ()
__warning__: ""
}
留存记录,希望也可以给你带来提示,加油,又是晴朗的一天~