user.ts 389 Bytes
Newer Older
hucy's avatar
hucy committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import { defineStore } from 'pinia';

export const userStore = defineStore('user', {
  state: () => {
    return {
      count: 1,
      arr: <any>[],
    };
  },
  getters: {
    myCount(state) {
      console.log('调用了myCount');
      return state.count + 1;
    },
  },
  actions: {
    changeState(num: number) {
      this.count += num;
      this.arr.push(num);
    },
  },
});