]> git.ipfire.org Git - thirdparty/vuejs/create-vue.git/commitdiff
feat: use setup stores in pinia example
authorHaoqun Jiang <haoqunjiang@gmail.com>
Tue, 23 Aug 2022 07:24:08 +0000 (15:24 +0800)
committerHaoqun Jiang <haoqunjiang@gmail.com>
Tue, 23 Aug 2022 07:26:47 +0000 (15:26 +0800)
Closes #94

template/config/pinia/src/stores/counter.js

index 4a2d24278dea7ef3ae4b0395047502ec6dc20475..b6757ba5723c5b89b35d011b9558d025bbcde402 100644 (file)
@@ -1,16 +1,12 @@
+import { ref, computed } from 'vue'
 import { defineStore } from 'pinia'
 
-export const useCounterStore = defineStore({
-  id: 'counter',
-  state: () => ({
-    counter: 0
-  }),
-  getters: {
-    doubleCount: (state) => state.counter * 2
-  },
-  actions: {
-    increment() {
-      this.counter++
-    }
+export const useCounterStore = defineStore('counter', () => {
+  const count = ref(0)
+  const doubleCount = computed(() => count.value * 2)
+  function increment() {
+    count.value++
   }
+
+  return { count, doubleCount, increment }
 })