menu.ts 626 B

123456789101112131415161718192021222324252627282930
  1. import {
  2. VuexModule,
  3. Module,
  4. getModule,
  5. Mutation,
  6. Action
  7. } from "vuex-module-decorators";
  8. import store from "../index";
  9. import { getMenu } from "@/api/menu";
  10. @Module({ dynamic: true, store, name: "menu" })
  11. class Menu extends VuexModule {
  12. private list = getMenu();
  13. @Mutation
  14. public setList(list: IMenu[]) {
  15. this.list = list;
  16. }
  17. get pList() {
  18. return this.list.filter(({ pId }) => !pId);
  19. }
  20. get subList() {
  21. return (pid: number) => this.list.filter(({ pId }) => pId === pid);
  22. }
  23. get info() {
  24. return (id: number) => this.list.find(x => x.id === id);
  25. }
  26. }
  27. export default getModule(Menu);