From 7089acacc2dc0f4cd2348fe09aededbd619eec7e Mon Sep 17 00:00:00 2001 From: lhj <403133128@qq.com> Date: Wed, 2 Oct 2024 20:41:44 +0800 Subject: [PATCH] =?UTF-8?q?pinia=E6=B7=BB=E5=8A=A0=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/TestComponent.vue | 21 +++++++++++++-------- src/stores/useSchemeStore.ts | 5 +++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/components/TestComponent.vue b/src/components/TestComponent.vue index 6aa7168..fdac0a9 100644 --- a/src/components/TestComponent.vue +++ b/src/components/TestComponent.vue @@ -9,10 +9,16 @@ function sub() { store.decrement() } -function initSchema() -{ - store.initSchema({ - name:"test" +function initScheme() { + store.initScheme({ + name: "test" + }) +} + +function updateScheme(value) { + store.$patch(state => { + state.scheme = { name: 'shoes', quantity: 1 } + state.hasChanged = true }) } @@ -21,8 +27,7 @@ function initSchema()
{{ store.count }}
add sub -
{{ store.schema }}
- initSchema - - +
{{ store.scheme }}
+ initScheme + updateScheme \ No newline at end of file diff --git a/src/stores/useSchemeStore.ts b/src/stores/useSchemeStore.ts index 12f94fe..1298a1a 100644 --- a/src/stores/useSchemeStore.ts +++ b/src/stores/useSchemeStore.ts @@ -12,10 +12,11 @@ export const useCounterStore = defineStore('counter', () => { function decrement() { count.value-- } - function initSchema(value) + function initScheme(value) { scheme.value=value } - return { count,scheme, doubleCount, increment,decrement,initSchema } + + return { count,scheme, doubleCount, increment,decrement,initScheme } }) \ No newline at end of file