const baseURL = "www.yhaha.com"
const service = (option) => {
option.url = `${baseURL}${option.url}`
option.header = {
'token': uni.getStorageSync(token)
}
return new Promise((resolve, reject) => {
uni.request(option).then((response) => {
let [error, res] = response
console.log('requestError:', error)
switch (res.statusCode) {
case 200:
if (res.data.errorMessage) {
uni.showToast({
title: res.data.errorMessage,
icon: 'error'
})
} else {
resolve(res.data)
}
break
case 401:
console.log('401')
break
}
}).catch(error => {
console.log('catchError:', error)
let [err, res] = error
reject(err)
})
})
}
export default service
import request from '@/utils/request.js/'
export default {
getData(data) {
return request({
url: "/data",
method: "POST",
data
})
},
}
import api from '@/utils/api.js';
Vue.prototype.$api = api
this.$api.getData(data).then((res)=>{
})