admin管理员组文章数量:1023195
How to add a global authorization header on nuxt.config.js?
tried
axios: {
defaults : {
headers : {
mon: [
{
'Authorization' : '5fb9c42ceba425fb9c42ceba43'
}
]
}
}
},
but not working
I can do
this.$axios.setHeader('Authorization', this.$store.state.appstore.akey);
but I find it not ideal when having multiple axios request because I have to add it on every request
How to add a global authorization header on nuxt.config.js?
tried
axios: {
defaults : {
headers : {
mon: [
{
'Authorization' : '5fb9c42ceba425fb9c42ceba43'
}
]
}
}
},
but not working
I can do
this.$axios.setHeader('Authorization', this.$store.state.appstore.akey);
but I find it not ideal when having multiple axios request because I have to add it on every request
Share Improve this question asked Nov 22, 2020 at 4:52 Juliver GalletoJuliver Galleto 9,05727 gold badges92 silver badges169 bronze badges2 Answers
Reset to default 3Try this, taken from the module docs.
axios: {
headers : {
mon: {
'Authorization' : '5fb9c42ceba425fb9c42ceba43'
}
}
}
I have created an plugin for it. Goto plugins
and create axios.js
:
export default function ({ $axios, store }) {
if (process.client) {
$axios.setToken(store.state.appstore.akey, 'Bearer')
}
}
Then register your plugin in nuxt.config.js
plugins: ['@/plugins/axios'],
How to add a global authorization header on nuxt.config.js?
tried
axios: {
defaults : {
headers : {
mon: [
{
'Authorization' : '5fb9c42ceba425fb9c42ceba43'
}
]
}
}
},
but not working
I can do
this.$axios.setHeader('Authorization', this.$store.state.appstore.akey);
but I find it not ideal when having multiple axios request because I have to add it on every request
How to add a global authorization header on nuxt.config.js?
tried
axios: {
defaults : {
headers : {
mon: [
{
'Authorization' : '5fb9c42ceba425fb9c42ceba43'
}
]
}
}
},
but not working
I can do
this.$axios.setHeader('Authorization', this.$store.state.appstore.akey);
but I find it not ideal when having multiple axios request because I have to add it on every request
Share Improve this question asked Nov 22, 2020 at 4:52 Juliver GalletoJuliver Galleto 9,05727 gold badges92 silver badges169 bronze badges2 Answers
Reset to default 3Try this, taken from the module docs.
axios: {
headers : {
mon: {
'Authorization' : '5fb9c42ceba425fb9c42ceba43'
}
}
}
I have created an plugin for it. Goto plugins
and create axios.js
:
export default function ({ $axios, store }) {
if (process.client) {
$axios.setToken(store.state.appstore.akey, 'Bearer')
}
}
Then register your plugin in nuxt.config.js
plugins: ['@/plugins/axios'],
本文标签: javascriptadd axios authorization on nuxt configStack Overflow
版权声明:本文标题:javascript - add axios authorization on nuxt config - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745530073a2154708.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论