config.js
const app = {
apiUrl: 'http://216:18080/webcase/', //要求的地点
baseRequest(obj) {
try {
const userToken = uni.getStorageSync('userToken');
if (userToken) {
if (obj.header) {
obj.header["token"] = userToken;
} else {
obj.header = { "token": userToken };
}
obj.url = this.apiUrl + obj.url;
uni.request(obj)
}
else{
console.log("猎取不到userToken")
}
} catch (e) {
console.log(e)
console.log("猎取不到userToken")
}
},
}
export default app;
须要运用的页面
import app from "@/api/apiConfig"
getUserStatus() {
app.baseRequest({
url: 'getUserStatus',
method: 'POST',
success: (res) => {
// 用户状况存到缓存中去
try{
uni.setStorageSync('userStatus', res.data.data.type)
uni.setStorageSync('userAgentInfo',res.data.data)
}catch(e){
//TODO handle the exception
}
if(res.data.data.type == 2) {
this.getLawInfo()
} else {
this.yhju= false
}
}
})
}