gpt4 book ai didi

vuejs2 - v-for 内部的 v-if 和 v-else 用于不同的文本渲染

转载 作者:行者123 更新时间:2023-12-04 10:03:11 27 4
gpt4 key购买 nike

我找不到一种方法来选择不同的选项来渲染 v-for 中的文本。是否有可能或者我是否需要以不同的方式构建逻辑来执行类似于下面的代码的操作?

<template>
<ul v-show="showNotifications">
<li v-for="notification in notifications">
// if notification.type = 'friend request'
New friend request from {{ notification.name }}
// else
New notification from {{ notification.name }}
</li>
</ul>
</template>

通知是一个包含名称和通知类型等数据的对象数组。

最佳答案

使用另一个 template元素如下(未测试)

<template>
<ul v-show="showNotifications">
<li v-for="notification in notifications">
<template v-if="notification.type == 'friend request'">
New friend request from {{ notification.name }}
</template>
<template v-else>
New notification from {{ notification.name }}
</template>
</li>
</ul>

关于vuejs2 - v-for 内部的 v-if 和 v-else 用于不同的文本渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42634908/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com