covidassist/src/store/index.js

41 lines
1 KiB
JavaScript
Raw Normal View History

2020-03-21 17:11:07 +01:00
import Vue from 'vue'
import Vuex from 'vuex'
2020-03-21 19:39:07 +01:00
import axios from 'axios';
2020-03-21 17:11:07 +01:00
2020-03-21 19:39:07 +01:00
Vue.use(Vuex)
2020-03-21 18:57:15 +01:00
export default new Vuex.Store({
state: {
surveyCompletedOnce: false,
2020-03-21 18:57:15 +01:00
answers: [],
2020-03-21 19:39:07 +01:00
questions: []
2020-03-21 18:57:15 +01:00
},
mutations: {
2020-03-22 00:33:29 +01:00
startWithFirstQuestion() {
this.state.currentQuestion = 0
},
2020-03-22 14:21:58 +01:00
answerQuestion(state, pl) {
this.state.answers[pl.id] = pl.answer
2020-03-21 20:20:55 +01:00
},
setSurveyCompleted() {
this.state.surveyCompletedOnce = true
},
2020-03-21 19:39:07 +01:00
init() {
axios.get('https://avian-safeguard-214619.firebaseio.com/questions.json')
.then(res => {
console.log(res)
this.state.questions = res.data
2020-03-21 21:54:20 +01:00
this.state.answers = Array.apply(0, Array(res.data.length)).map(function () {})
2020-03-21 19:39:07 +01:00
})
2020-03-21 18:57:15 +01:00
}
},
2020-03-21 21:54:20 +01:00
getters: {
numberQuestions: (state) => {
return state.questions.length
}
},
2020-03-21 19:39:07 +01:00
actions: {
},
2020-03-21 18:57:15 +01:00
modules: {}
2020-03-21 17:11:07 +01:00
})