count.ts 484 B

1234567891011121314151617181920212223
  1. import {defineStore} from 'pinia';
  2. export const useCountStore = defineStore('count1',{
  3. // 1.state 相当于 data 数组的存储
  4. state() {
  5. return {
  6. num: 666
  7. }
  8. },
  9. // 2.getters 相当于 computed 计算属性
  10. getters:{
  11. bigNum:(state:any)=>{
  12. return state.num * 5;;
  13. }
  14. },
  15. // 3.actions 相当于 methods 方法
  16. actions:{
  17. addThing(val:number) {
  18. this.num += val;
  19. }
  20. }
  21. });