Put the request processing in main.js:
axios.interceptors.response.use(
response => {
if (response.data.code != 0) {
return Promise.reject(response);
}
return response.data
}
)
It is found that when the code returned by the back end is not zero, that is, when return promise.rehect (response) is executed, although the code runs normally, the console will report an error:
vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in v-on handler (Promise/async): "[object Object]"
found in
---> <Login> at src/views/Login.vue
<App> at src/App.vue
<Root>
Find the problem on the Internet and find that the exception of promise.rehect (response) needs to be captured, but most of them are captured in the component. Isn’t it meaningless to put the judgment in the main file, so you can put the capture processing in the main file, as follows:
axios.interceptors.response.use(
response => {
if (response.data.code != 0) {
Message({content: response.data.message});
return Promise.reject(response).catch(()=>{});
}
return response.data
},
)
That is, add . Catch (() = & gt; {})
directly after promise. Rehect (response)
, which is currently valid for personal testing.
Read More:
- Error in v-on handler (Promise/async): “Error: Request failed with status code 500“
- Error in created hook: “referenceerror:” promise “undefined” Vue cli project Google is right, ie reported an error, “promise” undefined“
- Uncaught (in promise) Error: timeout of 5000ms exceeded
- Deep understanding of async await asynchronous programming synchronization
- ionic Uncaught (in promise): Error: StaticInjectorError[NavController]
- Error in v-on handler: “ReferenceError: XXX is not defined“
- Easywasmlayer reports an error uncaught (in promise) domexception when playing a video
- Uncaught (in promise) TypeError: Object(…) is not a function
- Vue Error in v-on handler: “TypeError: path.indexOf is not a function“
- Remove video with video byte 0, uncaught (in promise) domexception: failed to load because no supported source was f
- Vue router click the menu bar and the same module reports an error Vue router.esm.js? 2215:2065 Uncaught (in promise) Error
- Error 1: Vue quickly clicks the route to jump. Error: uncaught (in promise) error: request aborted
- Android “handler” is abstract; can’t be identified solution
- visual studio code (Error: Handler already set!)
- Solve the problem of permission after flutter package_ Handler failure
- Oracle error – ora-12519, TNS:no appropriate service handler found
- <info> peer_manager_handler: Connection security failed
- Ie11 reports an error unhandled promise rejection typeerror: the object does not support
- org.apache.catalina.LifecycleException: Protocol handler start failed