vuejs / vuex

🗃️ Centralized State Management for Vue.js.
https://vuex.vuejs.org
MIT License
28.4k stars 9.56k forks source link

In the VueX4.0, how to get the store object without setup, which is in the request_util.ts document #2024

Open happy0402 opened 3 years ago

happy0402 commented 3 years ago

What problem does this feature solve?

import {useStore} from 'vuex';

console.log(useStore()); //>> undefined

What does the proposed API look like?

//request_util.ts import {useStore} from 'vuex';

const store = useStore(); store.getter(['app/settoken']);

dboy2018 commented 3 years ago

StoreUtils.ts class StoreUtils { static store: any } export default StoreUtils

app.vue import StoreUtils from '@/utils/StoreUtils' export default defineComponent({ name: 'App', components: { }, setup() { const store = useStore() StoreUtils.store = store .......

other.ts import StoreUtils from '@/utils/StoreUtils' StoreUtils.store.getter(['app/settoken']);