【发布时间】:2023-03-26 04:18:01
【问题描述】:
我在 Vuex - VueJS 中使用 Axios Get with Header 遇到问题,希望大家帮助我。
页数:
<template>
<div class="temp">{{users.info}}</div>
</template>
<script>
data: function () {
return {
config: {
'headers': {'Authorization': 'JWT ' + this.$store.state.token}
}
}
},
fetch ({ store, params }) {
return store.dispatch('getProfile', params, this.config)
},
</script>
Vuex 模块:
import api from '~/plugins/axios'
const state = () => {
return {
info: null
}
}
const actions = {
getProfile ({commit}, params, config) {
return new Promise((resolve, reject) => {
api.get(`/users/${params.username}/`, config)
.then(response => {
commit('GET_USER_DETAIL', response.data)
resolve(response.data)
},
response => {
reject(response.data)
})
})
}
}
const getters = {}
const mutations = {
GET_USER_DETAIL (state, info) {
state.info = info
}
}
export default {
state,
actions,
getters,
mutations
}
问题:Vuex 模块中的配置未定义。
我认为我有问题希望您的帮助。 提前致谢!
【问题讨论】:
标签: vue.js axios vuex nuxt.js vuex-modules