使用composition api 的形式
使用组合式api的形式来创建store
只要导出就能调用
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
  | export const useCounterStore = defineStore('counter', () => {
  const count = ref(0)
  const name = ref('Eduardo')
  const doubleCount = computed(() => count.value * 2)
  function increment() {
    count.value++
  }
  return { count, name, doubleCount, increment }
})
  |