gpt4 book ai didi

vue.js - Vuex存储状态在控制台中未定义,但是Vue工具显示正常运行

转载 作者:行者123 更新时间:2023-12-03 06:43:51 25 4
gpt4 key购买 nike

我想在网络上显示我的 setter/getter ,但在console.log中我有未定义的错误。但是在vue开发工具中,我的 setter/getter 正在工作。

image 1

image 2

我的组件代码:

export default {
data: () => ({
items: [
{ text: 'Real-Time', icon: 'mdi-clock' },
{ text: 'Audience', icon: 'mdi-account' },
{ text: 'Conversions', icon: 'mdi-flag' },
],
}),
computed: {
Question(){
return this.$store.getters.getQuest
}
},
methods: {
Next(){
this.$store.commit('incrementIndex')
}
},

}

这是我的Vuex:
 export default new Vuex.Store({
state: {
question: [],
index: 0
},
getters: {
getQuest: state => {
let a = state.question[state.index]
let answer = [...a.incorrect_answers, a.correct_answer]
return {
question: a,
answer: answer
}
}

},

最佳答案

在getter中,您需要检查是否所有信息都已加载。所以这大概就是我要做的:

 export default new Vuex.Store({
state: {
question: [],
index: 0
},
getters: {
getQuest: state => {
let a = state.question[state.index]
if (a){
let answer = [...a.incorrect_answers, a.correct_answer]
return {
question: a,
answer: answer
}
} else {
return null
}

},

关于vue.js - Vuex存储状态在控制台中未定义,但是Vue工具显示正常运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61530694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com