vue3+ts+pinia

76 阅读1分钟

Dashboard.ts

import { defineStore } from 'pinia';

export const useGlobalAppIdStore = defineStore('myStore', {
  state: () => ({
    GlobalAppId: '',
  }),
  actions: {
    async changeId(appId) {
      this.GlobalAppId = appId
     
  
    },
  },
});

index.vue

import { useGlobalAppIdStore } from '@/store/modules/Dashboard';
const GlobalAppIdStore = useGlobalAppIdStore();
 GlobalAppIdStore.changeId(e);//设置值
onMounted(() => {
  configAppId.value = GlobalAppIdStore.GlobalAppId;//获取值
 
});