[Vuejs]-Correct way to dynamically change axios proxy URL?

0👍

You can change your export to be a method that accepts an URL and call it when you need to update it

const createAxios = (proxyURL) => {
 axios.create({
  baseURL: 'http://127.0.0.1',
  proxy: {
    '/api/': 'http://127.0.0.1',
    '/w0w/': proxyURL || 'http://192.168.1.12'
  }
 })
}

export default createAxios

Now you need to call it a bit differently

Vue.prototype.$axios = axios(/*or custom proxy url here*/);

Leave a comment