Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

nuxt.js - Problem on VueX getters reactivity (Nuxt project)

I am currently working on a draft questionnaire. I have started to encounter a problem that is preventing me from moving forward in this one. For information my project is in Nuxt.

Problematic :

The navigation of the questionnaire is done on a single page.It uses the store's getters to determine which page we should find ourselves on. However when I pass a page in full it does not change the display of the page as it should.

After several searches it turns out that it could come from the fact that I am going to look for my different pages in an array. However, I do not see how to solve this problem in a simple way and without having to redo my entire navigation system.

VueX Code :

// 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...