index.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { createStore } from 'vuex'
  2. // import { ActionContext } from 'vuex'
  3. import type { App } from 'vue'
  4. // 定义 RootState 接口(可扩展)
  5. interface RootState {
  6. count: number
  7. }
  8. // type StoreActionContext = ActionContext<RootState, RootState>
  9. // 创建 store 实例
  10. const store = createStore<RootState>({
  11. state: () => ({
  12. count: 0,
  13. horizontalMenuItems:[
  14. {
  15. title:'问卷管理',
  16. route:`/main`,
  17. childrenRoute:[
  18. '/main/createQuestionnaire',
  19. '/main/previewQuestionnaire'
  20. ]
  21. },
  22. {
  23. title:'评价管理',
  24. route:`/main/reviewManagement`,
  25. childrenRoute:[
  26. '/main/reviewManagementDetail'
  27. ]
  28. },
  29. {
  30. title:'评价分析',
  31. route:`/main/reviewAnalysis`,
  32. childrenRoute:[]
  33. },
  34. {
  35. title:'个人中心',
  36. route:`/main/personalCenter`,
  37. childrenRoute:[]
  38. },
  39. ]
  40. }),
  41. mutations: {
  42. increment(state: RootState) {
  43. state.count++
  44. }
  45. },
  46. actions: {
  47. increment({ commit }) {
  48. commit('increment')
  49. },
  50. },
  51. getters: {
  52. count: (state: RootState) => state.count,
  53. getDemo:(state)=>()=>{
  54. return state.horizontalMenuItems.map(item=>{
  55. return item
  56. })
  57. },
  58. }
  59. })
  60. // 提供一个方法用于注册到 Vue 应用中
  61. export function setupStore(app: App) {
  62. app.use(store)
  63. }
  64. export default store