Is there something like useKeyedRef? #10291
Unanswered
AmitJoki
asked this question in
Help/Questions
Replies: 1 comment 1 reply
-
If the component has local state that is independent of the route, and you want to use that component in a dynamic route like this, you use the key prop to let Vue (or rather here: vue-router) know when it should actually create a new component: <router-view v-slot="{ Component }">
<!-- key can have other values depending on the usecase/context -->
<component :is="Component" :key="$route.fullpath"
</router-view> |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Here's the scenario:
Let's say you have the following route entry:
And in
RouteComponent
you have the following code:Now with this setup,
computedProperty
is always going to be correct whenever we switch between multiple URLs. But thenormalRef
which is a regularref
won't. Since the component instance is cached updatingnormalRef
it in one url/foo/1
will reflect in/foo/2
when they both should have their own copies.This could be solved if we have a keyed ref. Here's an example composable:
Now we can do:
Here's a playground link. where clicking on 1, 2, 3 buttons is supposed to simulate different routes.
My questions are:
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions