How to use 2 instances of Axios with different baseURL in the same app (vue.js)

前端 未结 4 582
無奈伤痛
無奈伤痛 2021-01-01 15:41

I\'m trying to learn vue.js so I made a little app that displays news articles from an API and, in another view, allows the user to log into another server.

For this

4条回答
  •  隐瞒了意图╮
    2021-01-01 16:10

    You'll want to create a new instance of axios with a custom config for each API you want that has a distinct baseURL.

    var instance = axios.create({
      baseURL: 'https://some-domain.com/api/',
      timeout: 1000,
      headers: {'X-Custom-Header': 'foobar'}
    });
    

提交回复
热议问题