// VueX Store (it's a module : questionnaire)
export const state = () => ({
questionnaire: {
name: 'My questionnaire',
themes: [
{
name: 'theme 1',
started: true,
complete: false,
themePageAvailable: true,
nextButton: 'simple',
label: 'Hello welcome to theme 1',
questions: [
{
type: 'likert',
statement: "Question 1",
answer: null
},
{
type: 'likert',
statement: "Question 2",
answer: null
},
{
type: 'likert',
statement: "Question 3",
answer: null
},
]
},
{
name: 'theme 2',
started: false,
complete: false,
themePageAvailable: true,
nextButton: 'simple',
label: 'Hello welcome to theme 2',
questions: [
{
type: 'likert',
statement: "Question 1",
answer: null
},
{
type: 'likert',
statement: "Question 2",
answer: null
},
{
type: 'likert',
statement: "Question 3",
answer: null
},
]
},
]
},
})
export const getters = {
currentTheme (state) {
return state.questionnaire.filter(theme => theme.complete !== true)[0] || 'end'
},
}
export const mutations = {
SET_COMPLETE(state, currentTheme) {
currentTheme.complete = true
},
}
export const actions = {
setCompleteTheme({state, commit}, currentTheme) {
if (currentTheme.questions.some(question => question.answer === null)) {
console.error('test not complet')
} else {
commit('SET_COMPLETE', currentTheme)
}
},
}
question from:
https://stackoverflow.com/questions/65857039/problem-on-vuex-getters-reactivity-nuxt-project