import Vue from 'vue' import Vuex from 'vuex' import axios from 'axios'; import router from "@/router"; Vue.use(Vuex) export default new Vuex.Store({ state: { currentQuestion: 0, answers: [], questions: [] }, mutations: { nextQuestion() { if (this.state.currentQuestion < this.state.questions.length - 1) this.state.currentQuestion += 1 else { router.push('/results') } }, previousQuestion() { if (this.state.currentQuestion > 0) { this.state.currentQuestion -= 1 } }, answerQuestion(state, value) { this.state.answers[this.state.currentQuestion] = value }, 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.apply(0, Array(res.data.length)).map(function () {}) }) } }, getters: { numberQuestions: (state) => { return state.questions.length } }, actions: { }, modules: {} })