国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Vue 3 l?dt die Komponente neu, wenn sich die Variable ?ndert
P粉090087228
P粉090087228 2023-12-27 20:06:22
0
1
618

Ich versuche, die Komponente neu zuzuweisen, wenn sich die ausgew?hlte Liga ge?ndert hat

<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 der LeagueTopScorers-Komponente erhalte ich die API, um die besten Torschützen in der ausgew?hlten Liga zu ermitteln.

Ich habe versucht: watch, v-on:, erstellt()

P粉090087228
P粉090087228

Antworte allen(1)
P粉344355715

確實(shí)當(dāng)selectedLeague更改時(shí)重新渲染1,但它不會(huì)重新安裝。 僅當(dāng) selectedLeaguefalsy 值更改為 truthy 值時(shí)才會(huì)掛載(因?yàn)榇藭r(shí) v-if 更改)。

您的問(wèn)題存在一些問(wèn)題:

  • 您詢問(wèn)的是技術(shù)方面(我們稱之為 X),您認(rèn)為這將解決業(yè)務(wù)需求(我們稱之為 Y)。這是一個(gè)經(jīng)典的 XY 問(wèn)題。你為什么不描述 Y 的要求? (例如:您想要實(shí)現(xiàn)的目標(biāo))。您希望在輸入變化時(shí)看到什么輸出變化?
  • 您發(fā)布的代碼不足以創(chuàng)建可運(yùn)行示例。我們不知道 v-select 是什么, 是什么,或者 :is 屬性在 .

根據(jù)您發(fā)布的代碼片段,我猜測(cè)以下內(nèi)容:

  • v-selectvue-selectVuetify 選擇組件
  • 您期望 :is 上的工作方式與在 上的工作方式相同。提示:不會(huì),除非你自己編碼,我對(duì)此表示懷疑
  • 最后但并非最不重要的一點(diǎn)是,我想您希望將一些代碼放入 的 init 生命周期掛鉤中(例如:onMounted)在您將 selectedLeague 中存儲(chǔ)的對(duì)象替換為另一個(gè)對(duì)象。

如果我是正確的,實(shí)現(xiàn)此行為的最簡(jiǎn)單、最干凈的方法是創(chuàng)建一個(gè)計(jì)算2

const leagueId = computed(() => selectedLeague?.id.toString() || '')

...并在 v-if、:key:selectedLeague 中使用它:

<LeagueTopScorers
  v-if="leagueId"
  :selectedLeague="leagueId"
  :key="leagueId" />

(沒(méi)有

包裝器)。

每次 leagueId 更改時(shí),上面都會(huì)創(chuàng)建一個(gè) 的新實(shí)例,并且僅在 leagueId 不為 false 時(shí)渲染一個(gè)。我相信這就是您在技術(shù)上想要實(shí)現(xiàn)的目標(biāo)3


注釋:
1 - 要驗(yàn)證,請(qǐng)使用 onUpdated(() => console.log('updated...'))代碼>
2 - 如果selectedLeague,則使用selectedLeague.value?.id.toString()是一個(gè) ref
3 - 同時(shí),我確信無(wú)需創(chuàng)建 每次 leagueId 更改時(shí),但如果沒(méi)有更多詳細(xì)信息和/或上下文,我無(wú)法提供更多幫助

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage