Nuxt.js: Big gods, how do you configure Axios in the nuxt?(大神们,怎么在nuxt中全局配置axios啊?)

Created on 14 Dec 2017  ·  5Comments  ·  Source: nuxt/nuxt.js

For example, ask for teaching!(如题,求教!)

This question is available on Nuxt.js community (#c2075)

Most helpful comment

Hi sir. Please take a look at this module for axios integration: https://github.com/nuxt-community/axios-module

PS: Content-Type is usually set correctly by axios, so there is no need to customize it.

All 5 comments

是在.nuxt目录下面的index.js中配置么???

--.nuxt
   --index.js
import axios from 'axios'
Vue.prototype.$http = axios
axios.defaults.baseURL = host
axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded'
axios.defaults.headers['XPS-Version'] = '1.0.0'

这样对不对啊?

亲测,这样是对的,但是每次重新npm run dev的时候就会重新生成这个index.js把原来的覆盖掉,这个问题怎么解决呢?我估计是在nuxt.config.js里配置,但不知道怎么配,我在研究下

Hi sir. Please take a look at this module for axios integration: https://github.com/nuxt-community/axios-module

PS: Content-Type is usually set correctly by axios, so there is no need to customize it.

@pi0

Thank you sincerely!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nassimbenkirane picture nassimbenkirane  ·  3Comments

gary149 picture gary149  ·  3Comments

bimohxh picture bimohxh  ·  3Comments

vadimsg picture vadimsg  ·  3Comments

lazycrazy picture lazycrazy  ·  3Comments