监听state里的值变化

import { userStore } from "@store/user";
const user = userStore();

user.$subscribe((mutation: any, state: any) => {
  if (state.hospCode) {
    hospCode.value = state.hospCode
    // 刷新列表
    handleRefresh();
  }
});

store中的state

// store/user.ts
import { defineStore } from "pinia";
import Pinia from "./index";

export const userStore = defineStore("user", {
  state: () => ({
    hospCode:''
  }),
});

Logo

前往低代码交流专区

更多推荐