axios.js 667 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. * @Description:
  3. * @Author: 欧阳承珺
  4. * @LastEditors: 欧阳承珺
  5. * @Date: 2022-10-19 13:58:11
  6. * @LastEditTime: 2022-10-26 15:50:35
  7. */
  8. import { Message } from 'element-ui';
  9. export default function({store, app:{ $axios, rediret}} ) {
  10. $axios.onRequest(config => {
  11. $axios.setToken(store.state.token, 'Bearer')
  12. })
  13. $axios.onError(error => {
  14. const code = parseInt(error.response && error.response.status)
  15. if (code !== 200) {
  16. Message.error(error.response.data.msg)
  17. // redirect('/400')
  18. }
  19. })
  20. $axios.onResponse((res) => {
  21. if (res.data.code !== 200) {
  22. Message.error(res.data.msg)
  23. }
  24. return res.data
  25. })
  26. }