Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add useStore for v3 for vue 2.7 with composition api #2212

Open
ThomasKientz opened this issue Feb 22, 2023 · 5 comments
Open

Add useStore for v3 for vue 2.7 with composition api #2212

ThomasKientz opened this issue Feb 22, 2023 · 5 comments

Comments

@ThomasKientz
Copy link

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.

@yanyalin
Copy link

https://blog.csdn.net/qq_16139383/article/details/119935755
@ThomasKientz S
econdary packaging required

@dgautsch
Copy link

@ThomasKientz Did you find a workaround?

@ThomasKientz
Copy link
Author

@dgautsch no

@citrusjunoss
Copy link

I need the hook too.

@zlx362211854
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants