composition-api
composition-api copied to clipboard
vue2 use provide / inject ,get undefined
I created a component by vue2(v2.6.14). It use provide
and inject
in @vue/composition-api
to create a local state management.
export const initStore = () => {
const data = reactive([]);
provide('data1', data);
...
}
export const useStore = () => {
return {
data1: inject('data1');
....
}
}
In root component initStore
, and useStore
everywhere in component. In test, it looks OK.
When I publish package, and use it, all inject
returns undefined
. the custom component can not run normally.
It can not use like that or what do I need to do?
I met same problem
In development the currentInstance got object , when in production that's value got null
@jeremyjone Do you know how to reproduction?
Stale issue message
I solved the problem. Just fix the version number to v2.6.14
. Because npm is automatically installed in the latest version, which is v2.7.x
. They are in conflict.