add ability to save answers

This commit is contained in:
thilo 2020-03-21 21:54:20 +01:00
parent 5246711deb
commit 7b44071e0e
3 changed files with 41 additions and 2 deletions

View file

@ -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
}
]

View file

@ -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: {}

24
src/views/Results.vue Normal file
View file

@ -0,0 +1,24 @@
<template>
<div>
<p>Ihre Wahrscheinlichkeit sich zu infizieren ist</p>
</div>
</template>
<script>
export default {
name: "Results",
mounted() {
const biased = this.$store.state.answers.map((x, i) => {
return x * this.$store.state.questions[i].multiplicator
})
const summed = biased.reduce(function(acc, current) {
return acc + current
})
console.log(Math.round(summed / 10))
}
}
</script>
<style scoped>
</style>