-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
injected ref value is not reactive when updated inside setup of a child component #2043
Comments
The usage here is different from the document. 🧐
|
@Picknight |
The deep reason is ac81dcf. @yyx990803 Maybe we should revert it ? |
I see this issue is closed but I am not seeing any conclusion on this thread. Am I missing something? I am also looking for solution to my problem. |
I'm trying to inject a Boolean value into all components (SFC), which provide/inject seems best suited for. I have Vue 3.1.2. I tried calling: const injectedRef = ref(getCurrentState())
app.provide('injectedName', injectedRef) const injectedComputed = computed(() => injectedRef)
app.provide('injectedName', injectedComputed) const injectedReactive = reactive({ injectedRef })
app.provide('injectedName', injectedReactive) As you can see, only the last method worked, but that defeats the purpose of injecting a single true/false variable that can be used directly in components. This was previously done with: const reactiveProxy = Vue.observable({ state: getCurrentState() })
Vue.use({
install (vueInstance) {
Object.defineProperty(vueInstance.prototype, '$injectedName', {
get: () => reactiveProxy.state
})
}
}) |
Version
3.0.0-rc.10
Reproduction link
https://codesandbox.io/s/admiring-snow-4u748?file=/src/Child.vue
Steps to reproduce
Open the reproduction link, in parent component setup we have:
and in a child component setup:
What is expected?
the screen should show: "updated"
What is actually happening?
the screen shows "initial"
It works fine when wrapped inside a lifecycle hook:
I'm not sure if it's a bug or intentional behavior, but I find it weird since the parent's setup function is executed before the child's.
The text was updated successfully, but these errors were encountered: