import { defineStore } from "pinia";
const useCounter = defineStore("counter", {
  state: () => ({
    count: 66,
  }),
  getters: {
    //基本使用
    doubleCount(state) {
      return state.count * 2;
    },
  },

  actions: {
    increment(state) {
      //actions没有state，只能通过this拿store，这里打印
      //state的结果是undefined 所以actions只能通过this访问store。getter的话state和this都能访问。
      console.log(state);
      this.count++;
    },
    incrementNum(num) {
      this.count += num;
    },
  },
  // 是否持久化存储
  persist: true,
});

//暴露这个useCounter模块
export default useCounter;
