add ability to save answers
This commit is contained in:
parent
5246711deb
commit
7b44071e0e
3 changed files with 41 additions and 2 deletions
|
@ -3,6 +3,7 @@ import VueRouter from 'vue-router'
|
||||||
import Home from '../views/Home.vue'
|
import Home from '../views/Home.vue'
|
||||||
import Warning from '../views/Warning'
|
import Warning from '../views/Warning'
|
||||||
import Questionnaire from "@/views/Questionnaire";
|
import Questionnaire from "@/views/Questionnaire";
|
||||||
|
import Results from "@/views/Results";
|
||||||
|
|
||||||
Vue.use(VueRouter)
|
Vue.use(VueRouter)
|
||||||
|
|
||||||
|
@ -21,6 +22,11 @@ const routes = [
|
||||||
path: '/questionmaire',
|
path: '/questionmaire',
|
||||||
name: 'Fragebogen',
|
name: 'Fragebogen',
|
||||||
component: Questionnaire
|
component: Questionnaire
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/results',
|
||||||
|
name: 'Ergebnisse',
|
||||||
|
component: Results
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import router from "@/router";
|
||||||
|
|
||||||
|
|
||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
@ -13,9 +14,12 @@ export default new Vuex.Store({
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
nextQuestion() {
|
nextQuestion() {
|
||||||
if (this.state.currentQuestion <=
|
if (this.state.currentQuestion <
|
||||||
this.state.questions.length - 1)
|
this.state.questions.length - 1)
|
||||||
this.state.currentQuestion += 1
|
this.state.currentQuestion += 1
|
||||||
|
else {
|
||||||
|
router.push('/results')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
previousQuestion() {
|
previousQuestion() {
|
||||||
if (this.state.currentQuestion > 0) {
|
if (this.state.currentQuestion > 0) {
|
||||||
|
@ -30,10 +34,15 @@ export default new Vuex.Store({
|
||||||
.then(res => {
|
.then(res => {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
this.state.questions = res.data
|
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: {
|
actions: {
|
||||||
},
|
},
|
||||||
modules: {}
|
modules: {}
|
||||||
|
|
24
src/views/Results.vue
Normal file
24
src/views/Results.vue
Normal 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>
|
Loading…
Reference in a new issue