covidassist/src/store/index.js

47 lines
1.2 KiB
JavaScript

import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios';
Vue.use(Vuex)
export default new Vuex.Store({
state: {
surveyCompletedOnce: false,
answers: [],
skipped: [],
questions: []
},
mutations: {
startWithFirstQuestion() {
this.state.currentQuestion = 0
},
answerQuestion(state, pl) {
this.state.skipped[pl.id] = false
this.state.answers[pl.id] = pl.answer
},
setSkipped(state, n) {
this.state.skipped[n] = true
},
setSurveyCompleted() {
this.state.surveyCompletedOnce = true
},
init() {
axios.get('https://avian-safeguard-214619.firebaseio.com/questions.json')
.then(res => {
console.log(res)
this.state.questions = res.data
this.state.answers = Array(res.data.length).fill(0);
this.state.skipped = Array(res.data.length).fill(false);
})
}
},
getters: {
numberQuestions: (state) => {
return state.questions.length
}
},
actions: {
},
modules: {}
})