【发布时间】:2019-08-14 17:49:36
【问题描述】:
我在我的 cue 项目中使用 axios,并尝试设置一些自定义默认设置来使用它。
所以我做了一个 axios.js 文件
import axios from 'axios'
const API_URL = 'http://localhost:8081'
export default axios.create({
baseUrl: API_URL,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + localStorage.token
}
})
然后我使用我的 axios 将它安装在 /components/axios/index.js 中
import Vue from 'vue'
import VueAxios from 'vue-axios'
import axios from './axios'
Vue.use(VueAxios, axios)
这样我应该用我的设置全局设置 axios 吧?
所以在我的 Login.vue 组件文件中我调用了这个方法
login() {
this.$http
.post("/oauth/token", {
username: this.email,
password: this.password,
client_id: "test",
client_secret: "test",
grant_type: "password"
},
)
.then(request => this.loginSuccessful(request))
.catch(() => this.loginFailed());
}
但是$http 没有我的自定义设置而是 axios 通用
【问题讨论】: