vuex
vuex copied to clipboard
Add useStore for v3 for vue 2.7 with composition api
What problem does this feature solve?
Vue 2.7 supports composition API but we can't use it with Vuex (v3).
What does the proposed API look like?
Porting useStore
from v4 to v3. Or make v4 compatible with vue 2.7.
https://blog.csdn.net/qq_16139383/article/details/119935755 @ThomasKientz S econdary packaging required
@ThomasKientz Did you find a workaround?
@dgautsch no
I need the hook too.
You can create your own useStore,
// utils file
import {getCurrentInstance} from 'vue'
export const useStore = () => {
const vm = getCurrentInstance();
if (!vm) throw new Error('must be called in setup');
return vm.proxy.$store;
};
You can use it anywhere you want:
import { useStore } from '@/utils/index';
const store = useStore();
@ThomasKientz