From: Haoqun Jiang Date: Tue, 23 Aug 2022 07:24:08 +0000 (+0800) Subject: feat: use setup stores in pinia example X-Git-Tag: v3.3.3~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f144f0ff3440d82f8d7d2559a66101c1835fde9;p=thirdparty%2Fvuejs%2Fcreate-vue.git feat: use setup stores in pinia example Closes #94 --- diff --git a/template/config/pinia/src/stores/counter.js b/template/config/pinia/src/stores/counter.js index 4a2d2427..b6757ba5 100644 --- a/template/config/pinia/src/stores/counter.js +++ b/template/config/pinia/src/stores/counter.js @@ -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 } })