Change the default base url for axios

前端 未结 4 1280
耶瑟儿~
耶瑟儿~ 2021-02-01 12:42

I have configured my axios like this

const axiosConfig = {
  baseURL: \'http://127.0.0.1:8000/api\',
  timeout: 30000,
};

Vue.prototype.$axios = axios.create(ax         


        
4条回答
  •  北恋
    北恋 (楼主)
    2021-02-01 13:02

    From axios docs you have baseURL and url

    baseURL will be prepended to url when making requests. So you can define baseURL as http://127.0.0.1:8000 and make your requests to /url

    // 
    `url` is the server URL that will be used for the request
      url: '/user',
    
      // `baseURL` will be prepended to `url` unless `url` is absolute.
      // It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
      // to methods of that instance.
      baseURL: 'https://some-domain.com/api/',
    
    

提交回复
热议问题