1

Here's a reproduction link: https://stackblitz.com/edit/node-c6mn17?file=src/components/Test.vue

I want to be able to use reactive state from that store using setup in Vue 2.7.

I export a Vuex store using export const store = new Vuex.Store({ ... })

Both of these fail:

const count1 = store.state.count;
const count2 = ref(store.state.count);

Doesn't work when exporting the store as a function either: export const useStore = () => store and doing useStore().state ...

0

2 Answers 2

1

use computed:

import { computed } from "vue"

const count2 = computed(() => store.state.count);
Sign up to request clarification or add additional context in comments.

Comments

0

Or toRef/toRefs

const { count } = toRefs(store.state);
const count1 = toRef(store.state, "count");

Stackblitz

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.