From 9e40309e5bfc54f5f71178cf90d37ebcf8dd8dca Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Sun, 5 Sep 2021 20:18:08 +0200 Subject: [PATCH] fix: correctly set the store properties in Vue 2 Fix #657 --- packages/pinia/src/store.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/pinia/src/store.ts b/packages/pinia/src/store.ts index 66cd9eb5..b77f1f2f 100644 --- a/packages/pinia/src/store.ts +++ b/packages/pinia/src/store.ts @@ -491,7 +491,18 @@ function createSetupStore< } // add the state, getters, and action properties - assign(store, setupStore) + if (isVue2) { + Object.keys(setupStore).forEach((key) => { + set( + store, + key, + // @ts-expect-error: valid key indexing + setupStore[key] + ) + }) + } else { + assign(store, setupStore) + } // use this instead of a computed with setter to be able to create it anywhere // without linking the computed lifespan to wherever the store is first -- 2.47.3