vuex icon indicating copy to clipboard operation
vuex copied to clipboard

Add useStore for v3 for vue 2.7 with composition api

Open ThomasKientz opened this issue 2 years ago • 5 comments

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.

ThomasKientz avatar Feb 22 '23 08:02 ThomasKientz

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

yanyalin avatar Feb 24 '23 09:02 yanyalin

@ThomasKientz Did you find a workaround?

dgautsch avatar May 24 '23 14:05 dgautsch

@dgautsch no

ThomasKientz avatar May 24 '23 14:05 ThomasKientz

I need the hook too.

citrusjunoss avatar Jul 20 '23 07:07 citrusjunoss

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

zlx362211854 avatar Sep 12 '23 08:09 zlx362211854