axios.interceptors.response.use(
response => {
if (response.data.code === "OK") {
return response
} else if (response.data.code === "ERROR") {
console.log(response.data.data)
return Promise.reject(response.data)
}
},
error => {
...
})
then encapsulate the axios with a layer
export const Common = {
axios (url, params) {
params = params || {}
return axios.post(url, qs.stringify(params))
}
}
use it
Common.axios("/api/a", { a: 1 }).then().catch(e => {})
catch exceptions every time. Can this catch exception be handled uniformly =. =