vuejs / composition-api

Composition API plugin for Vue 2
https://composition-api.vuejs.org/
MIT License
4.19k stars 343 forks source link

vue2 use provide / inject ,get undefined #964

Closed jeremyjone closed 1 year ago

jeremyjone commented 2 years ago

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?

JerryWu1234 commented 1 year ago

I met same problem

JerryWu1234 commented 1 year ago

In development the currentInstance got object , when in production that's value got null

JerryWu1234 commented 1 year ago

@jeremyjone Do you know how to reproduction?

github-actions[bot] commented 1 year ago

Stale issue message

jeremyjone commented 1 year ago

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.