Three issues with Axios (added in main.js)

import axios from 'axios'
Copy the code

1: base path

axios.defaults.baseURL = 'http://localhost:8888/api/private/v1/'
Copy the code

2: Introduce Axios every time

Vue.prototype.$axios = axios
Copy the code

3: intercepts each request and carries the token

 axios.defaults.headers.common['Authorization'] = localStorage.getItem('token')
axios.interceptors.request.use(
  function (config) {
    
    config.headers.Authorization = localStorage.getItem('token')

    return config
  },
  function (error) {
    // Do something with request error
    return Promise.reject(error)
  }
)
Copy the code

For details, see github.com/axios/axios