From 7b44071e0e7a3eefe524ff7dedb8c3beb5c79ab4 Mon Sep 17 00:00:00 2001 From: thilo Date: Sat, 21 Mar 2020 21:54:20 +0100 Subject: [PATCH] add ability to save answers --- src/router/index.js | 6 ++++++ src/store/index.js | 13 +++++++++++-- src/views/Results.vue | 24 ++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/views/Results.vue diff --git a/src/router/index.js b/src/router/index.js index 8fa89ff..f8265d3 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -3,6 +3,7 @@ import VueRouter from 'vue-router' import Home from '../views/Home.vue' import Warning from '../views/Warning' import Questionnaire from "@/views/Questionnaire"; +import Results from "@/views/Results"; Vue.use(VueRouter) @@ -21,6 +22,11 @@ const routes = [ path: '/questionmaire', name: 'Fragebogen', component: Questionnaire + }, + { + path: '/results', + name: 'Ergebnisse', + component: Results } ] diff --git a/src/store/index.js b/src/store/index.js index 1f90c16..73153c1 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,6 +1,7 @@ import Vue from 'vue' import Vuex from 'vuex' import axios from 'axios'; +import router from "@/router"; Vue.use(Vuex) @@ -13,9 +14,12 @@ export default new Vuex.Store({ }, mutations: { nextQuestion() { - if (this.state.currentQuestion <= + if (this.state.currentQuestion < this.state.questions.length - 1) this.state.currentQuestion += 1 + else { + router.push('/results') + } }, previousQuestion() { if (this.state.currentQuestion > 0) { @@ -30,10 +34,15 @@ export default new Vuex.Store({ .then(res => { console.log(res) this.state.questions = res.data - this.state.answers = Array.apply(null, Array(res.data.length)).map(function () {}) + this.state.answers = Array.apply(0, Array(res.data.length)).map(function () {}) }) } }, + getters: { + numberQuestions: (state) => { + return state.questions.length + } + }, actions: { }, modules: {} diff --git a/src/views/Results.vue b/src/views/Results.vue new file mode 100644 index 0000000..6fc8747 --- /dev/null +++ b/src/views/Results.vue @@ -0,0 +1,24 @@ + + + + +