添加store
This commit is contained in:
13
src/App.vue
13
src/App.vue
@@ -14,18 +14,11 @@ import correct from './assets/sound/correct.wav'
|
||||
import {chunk} from "lodash"
|
||||
import {$ref} from "vue/macros"
|
||||
import {useSound} from "@/hooks/useSound.ts"
|
||||
import {useBaseStore} from "@/stores/base.ts"
|
||||
import {Config, Word} from "@/types.ts"
|
||||
// import {$ref, $computed} from 'vue/macros'
|
||||
// import MCE_3 from './assets/dicts/NCE_3.json'
|
||||
|
||||
type Config = {
|
||||
newWords: Word[],
|
||||
skipWords: Word[],
|
||||
skipWordNames: string[],
|
||||
dict: string,
|
||||
chapterIndex: number,
|
||||
wordIndex: number,
|
||||
}
|
||||
type Word = {"name": string, "usphone": string, "ukphone": string, "trans": string[]}
|
||||
let wordList: Word[][] = $ref([])
|
||||
let input = $ref('')
|
||||
let wrong = $ref('')
|
||||
@@ -39,6 +32,8 @@ let config: Config = $ref({
|
||||
wordIndex: 0,
|
||||
})
|
||||
|
||||
const store = useBaseStore()
|
||||
|
||||
// const [play, setAudio] = useSound([机械0, 机械1, 机械2, 机械3], 1)
|
||||
const [play, setAudio] = useSound([老式机械], 3)
|
||||
// const [play, setAudio] = useSound([电话打字的声音Mp3], 3)
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { createApp } from 'vue'
|
||||
import {createApp} from 'vue'
|
||||
import './style.css'
|
||||
import App from './App.vue'
|
||||
import {createPinia} from "pinia"
|
||||
|
||||
createApp(App).mount('#app')
|
||||
const pinia = createPinia()
|
||||
const app = createApp(App)
|
||||
|
||||
app.use(pinia)
|
||||
app.mount('#app')
|
||||
26
src/stores/base.ts
Normal file
26
src/stores/base.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import {defineStore} from 'pinia'
|
||||
import {Config, Word} from "../types.ts"
|
||||
|
||||
export const useBaseStore = defineStore('base', {
|
||||
state: () => ({
|
||||
newWords: [],
|
||||
skipWords: [],
|
||||
skipWordNames: [],
|
||||
dict: 'nce2',
|
||||
chapterIndex: 0,
|
||||
wordIndex: 0,
|
||||
}
|
||||
),
|
||||
getters: {
|
||||
word: (state): Word => {
|
||||
return state.wordList?.[state.chapterIndex]?.[state.wordIndex] ?? {
|
||||
trans: [],
|
||||
name: ''
|
||||
}
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
init(config: Config) {
|
||||
},
|
||||
},
|
||||
})
|
||||
9
src/types.ts
Normal file
9
src/types.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export type Config = {
|
||||
newWords: Word[],
|
||||
skipWords: Word[],
|
||||
skipWordNames: string[],
|
||||
dict: string,
|
||||
chapterIndex: number,
|
||||
wordIndex: number,
|
||||
}
|
||||
export type Word = {"name": string, "usphone": string, "ukphone": string, "trans": string[]}
|
||||
Reference in New Issue
Block a user