Change the default base url for axios

前端 未结 4 1281
耶瑟儿~
耶瑟儿~ 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:22

    Instead of

    this.$axios.get('items')
    

    use

    this.$axios({ url: 'items', baseURL: 'http://new-url.com' })
    

    If you don't pass method: 'XXX' then by default, it will send via get method.

    Request Config: https://github.com/axios/axios#request-config

提交回复
热议问题