You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
695 B

2 years ago
  1. export default ({ app, $axios, store, redirect }, inject) => {
  2. $axios.defaults.timeout = 5000;
  3. // 請求攔截
  4. $axios.onRequest((config) => {
  5. // token 儲存在緩存
  6. console.log("axios.onRequest");
  7. })
  8. // 服務器返回異常攔截
  9. $axios.onError((error) => {
  10. const code = parseInt(error && error.response && error.response.status)
  11. if (code === 401) {
  12. app.$auth.$storage.removeUniversal('userPicture')
  13. app.$auth.$storage.removeUniversal('userLastName')
  14. app.$auth.$storage.removeUniversal('jwt')
  15. app.$auth.logout()
  16. }
  17. return error
  18. })
  19. // 接口數據返回攔截
  20. $axios.onResponse((response) => {
  21. return response
  22. })
  23. }