Pinia状态管理实战教程

使用

import { surveyPageStore } from '@/store/modules/survey-page'; import { storeToRefs } from "pinia"; const surveyPage = surveyPageStore() const { selectType } = storeToRefs(surveyPage) selectType.value 就是值

survey-page.js

export const surveyPageStore = defineStore('survey-page', () => { const selectType = ref("report") // const selectType = ref("num") const table_name = ref("") const record_uuid = ref("") const file_list = ref([]) const menuName = ref("") return { selectType, table_name, record_uuid,file_list,menuName } })

@/store/index.js

const store = createPinia() export default store