【发布时间】:2019-02-16 22:24:17
【问题描述】:
我是 Vue.js 新手,想在组件中向受限 api 发出请求:
computed: {
token () {
return this.$store.getters.getToken;
},
...
created () {
axios
.get( this.BASE_URL + '/profile/me')
.then( res => {
this.profile = res.data;
console.log('profile is:', res.data);
})
.catch(error => console.log(error))
},
问题是我不知道如何将令牌包含到请求标头中。所以毫不奇怪,我得到401 错误响应。
当我尝试时
axios.defaults.headers.common['Authorization'] = this.token;
在获取请求之前,我在服务器日志中收到OPTIONS /profile/me 而不是GET /profile/me。
我该如何解决?
【问题讨论】:
标签: javascript express vue.js axios