I'm trying to reassign the component if selectedLeague has changed
<label class="label">Select league</label> <div class="selector"> <v-select v-model="selectedLeague" :dropdown-should-open="dropdownShouldOpen" :options="leagues" label="displayLeague" placeholder="Select a league" /> </div> <div v-if="selectedLeague"> <LeagueTopScorers :is="selectedLeague" :selectedLeague="selectedLeague.id.toString()" /> </div>
In the LeagueTopScorers component I am getting the API to get the top scorers in the selected league.
I tried: watch, v-on:, created()
IndeedRe-render whenselectedLeague
changes1 , but it won't reinstall. It will only be mounted ifselectedLeague
changes from the falsy value to the truthy value (because that's whenv-if changes).
There are some problems with your question:
v-select
is, what
is, or what the:is
attribute is in
.Based on the code snippet you posted, I'm guessing the following:
v-select
is vue-select or Vuetify select component:is
to work the same way on
as it does on
. Tip: No, unless you code it yourself, which I doubt
(for example:onMounted
) in your Replaces the object stored inselectedLeague
with another object.If I'm correct, the simplest and cleanest way to achieve this behavior is to create a calculation 2:
...and use it in
v-if
,:key
and:selectedLeague
:(without wrapper).
Every time
leagueId
changes, the above creates a new instance of
and only renders one ifleagueId
is not false. I believe this is what you are technically trying to achieve3.Comments:
1 - To verify, use
onUpdated(() => console.log('updated...'))代码>
2 - Use
selectedLeague.value?.id.toString() if
selectedLeagueis a
ref3 - Also, I'm sure there's no need to create the
every time the
leagueIdchanges, but if not I can't be of more help with more details and/or context