Vuetify 2 到 3 迁移:当 v-list-item-icon 具有 v-if 条件时该怎么办

huangapple go评论41阅读模式
英文:

Vuetify 2->3 Migration: what to do when v-list-item-icon has a v-if conditional

问题

I have reworked this post to just be about v-list-item-icon; if you are arriving here looking for that, there is an answer down below.

这篇文章已经重新编辑,只涉及到 v-list-item-icon;如果您是为了寻找相关信息而来,下面有答案。

It was suggested in a comment that since I was asking a number of migration questions, I split this into multiple posts. I have done so now. These are those posts:

有人在评论中建议,因为我提出了许多迁移问题,所以将其拆分为多个帖子。我现在已经这样做了。这些是那些帖子:

Someone already helped me with the v-list-item-icon issue, though, so I am reworking the rest of this post to just be about that in case someone else finds this.

不过,有人已经帮助我解决了 v-list-item-icon 的问题,所以我正在重新编辑这篇文章,以便其他人找到时只涉及这个问题。

The migration guide says a number of properties has been removed, but the docs are incredibly vague on what to do to replace them.

迁移指南 表示已删除了一些属性,但文档对于替代方法非常模糊不清。

I am not a front-end dev, but I've been tasked with updating some very old dependencies, and part of that is migrating from Vuetify 2 to Vuetify 3. I've done my best to follow the migration guide, but I'm having trouble with v-list-item-icon.

不是前端开发者,但我被要求更新一些非常旧的依赖项,其中一部分是从 Vuetify 2 迁移到 Vuetify 3。我已尽力遵循迁移指南,但在 v-list-item-icon 部分遇到了问题。

While it seems clear I need to replace

虽然似乎很明显我需要替换

<v-list-item
  class="mr"
  v-for="item in userItems"
  :key="item.title"
  link
  @click="clickUserMenuItem(item.routeName)"
>
  <v-list-item-icon>
    <v-icon>{{ item.icon }}</v-icon>
  </v-list-item-icon>

with

用以下内容替换

<v-list-item
  class="mr"
  v-for="item in userItems"
  :key="item.title"
  link
  @click="clickUserMenuItem(item.routeName)"
  icon="{{item.icon}}"
>

it is not clear what to do if I have

如果我有以下代码,不太清楚该怎么办:

<v-list-item-icon v-if="item.icon">
  <v-icon>{{ item.icon }}</v-icon>
</v-list-item-icon>

... do I need icon="{{v-if={{item.icon}}}}"?

...是否需要 icon="{{v-if={{item.icon}}}}"

Thank you!

谢谢!

英文:

I have reworked this post to just be about v-list-item-icon; if you are arriving here looking for that, there is an answer down below.

It was suggested in a comment that since I was asking a number of migration questions, I split this into multiple posts. I have done so now. These are those posts:

Someone already helped me with the v-list-item-icon issue, though, so I am reworking the rest of this post to just be about that in case someone else finds this.


The migration guide says a number of properties has been removed, but the docs are incredibly vague on what to do to replace them.

I am not a front-end dev, but I've been tasked with updating some very old dependencies, and part of that is migrating from Vuetify 2 to Vuetify 3. I've done my best to follow the migration guide, but I'm having trouble with v-list-item-icon.

While it seems clear I need to replace

&lt;v-list-item
  class=&quot;mr&quot;
  v-for=&quot;item in userItems&quot;
  :key=&quot;item.title&quot;
  link
  @click=&quot;clickUserMenuItem(item.routeName)&quot;
&gt;
  &lt;v-list-item-icon&gt;
    &lt;v-icon&gt;{{ item.icon }}&lt;/v-icon&gt;
  &lt;/v-list-item-icon&gt;

with

&lt;v-list-item
  class=&quot;mr&quot;
  v-for=&quot;item in userItems&quot;
  :key=&quot;item.title&quot;
  link
  @click=&quot;clickUserMenuItem(item.routeName)&quot;
  icon=&quot;{{item.icon}}&quot;
&gt;

it is not clear what to do if I have

&lt;v-list-item-icon v-if=&quot;item.icon&quot;&gt;
  &lt;v-icon&gt;{{ item.icon }}&lt;/v-icon&gt;
&lt;/v-list-item-icon&gt;

... do I need icon=&quot;{{v-if={{item.icon}}}}&quot;?

Thank you!

答案1

得分: 1

<v-list-item
  class="mr"
  v-for="item in userItems"
  :key="item.title"
  link
  @click="clickUserMenuItem(item.routeName)"
  :icon="item.icon || null"
/>

你真的不需要使用 'item.icon || null',只使用 'item.icon' 就足够了。

参考这个回答:
https://stackoverflow.com/questions/42874314/vuejs-conditionally-add-an-attribute-for-an-element/64598898#64598898


<details>
<summary>英文:</summary>

<v-list-item
class="mr"
v-for="item in userItems"
:key="item.title"
link
@click="clickUserMenuItem(item.routeName)"
:icon="item.icon || null"
/>

you really do not need it with &#39;item.icon || null&#39; &lt; &#39;item.icon&#39; would be enough..

see this answer: 
https://stackoverflow.com/questions/42874314/vuejs-conditionally-add-an-attribute-for-an-element/64598898#64598898

</details>



huangapple
  • 本文由 发表于 2023年5月11日 12:59:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76224267.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定