Problem Description: The data obtained using axios was successful, but the obtained data did not successfully enter the warehouse. There is an array in the warehouse, and the content of the array is empty. Vscode did not report an error, and then I tried to restart the server and console still reported an error.
Relevant code:
- Error code:
index.js?8626:14 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'code') at Store.getCategoryList
2.axios request code:
api/index.js file:
export const reqGetCategoryList = () => {
requests.get('/product/getBaseCategoryList')}
home/index.js file:
import { reqGetCategoryList } from "@/api"
const state = {
categoryList: []
}
const mutations = {
CATEGORYLIST(state, categoryList) {
state.categoryList = categoryList
}
}
const actions = {
async getCategoryList({ commit }) {
let result = await reqGetCategoryList();
if (result.code==200) {
commit("CATEGORYLIST", result.data)
}
}
}
const getters = {}
export default {
state,
mutations,
actions,
getters
}
What are you expecting results? What is the actual error message you see?
The repository content I am expecting is categoryList:Array[17]
The content of the warehouse after the error is categoryList:Array[0]