Added pinia and stores
This commit is contained in:
parent
6451073a62
commit
17e15712af
@ -2,7 +2,9 @@ import { createApp } from 'vue'
|
||||
import '@/style.css'
|
||||
import App from '@/App.vue'
|
||||
import Router from '@/router'
|
||||
import { createPinia } from 'pinia'
|
||||
import '@/assets/js/quiz.js'
|
||||
const app = createApp(App)
|
||||
app.use(createPinia())
|
||||
app.use(Router)
|
||||
app.mount('#app')
|
||||
|
22
client/src/stores/answers.js
Normal file
22
client/src/stores/answers.js
Normal file
@ -0,0 +1,22 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useAnswersStore = defineStore({
|
||||
id: 'answers',
|
||||
state: () => ({
|
||||
answers: [],
|
||||
}),
|
||||
actions: {
|
||||
isAnswered(index) {
|
||||
if (!Array.isArray(this.answers[index]) ) {
|
||||
return this.answers[index] != null
|
||||
} else {
|
||||
return this.answers[index].length > 0
|
||||
}
|
||||
},
|
||||
makeArray(index, selectNumber) {
|
||||
if (selectNumber > 1 && !Array.isArray(this.answers[index])) {
|
||||
this.answers[index] = [ ]
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
18
client/src/stores/app.js
Normal file
18
client/src/stores/app.js
Normal file
@ -0,0 +1,18 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useAppStore = defineStore({
|
||||
id: 'app',
|
||||
state: () => ({
|
||||
hasData: false,
|
||||
results: {}
|
||||
}),
|
||||
actions: {
|
||||
toggleData() {
|
||||
this.hasData = !this.hasData
|
||||
console.log('Toggled Has Data. New value', this.hasData)
|
||||
},
|
||||
storeResults(results) {
|
||||
this.results = JSON.parse(JSON.stringify(results))
|
||||
}
|
||||
}
|
||||
})
|
20
client/src/stores/questions.js
Normal file
20
client/src/stores/questions.js
Normal file
@ -0,0 +1,20 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useQuestionStore = defineStore({
|
||||
id: 'questions',
|
||||
state: () => ({
|
||||
questions: [],
|
||||
currentQuestion: 0
|
||||
}),
|
||||
actions: {
|
||||
storeQuestions(questionArray) {
|
||||
this.questions = [...questionArray]
|
||||
},
|
||||
nextQuestion() {
|
||||
this.currentQuestion ++
|
||||
},
|
||||
previousQuestion() {
|
||||
this.currentQuestion --
|
||||
}
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue
Block a user