vue case when
时间: 2023-12-20 18:32:50 浏览: 139
根据提供的引用内容,Vue中没有直接的"case when"语法,但可以使用插槽和条件渲染来实现类似的功能。下面是一个示例:
```html
<template>
<div>
<div v-for="item in items" :key="item.id">
<slot :name="getSlotName(item)"></slot>
</div>
</div>
</template>
<script>
export default {
data() {
return {
items: [
{ id: 1, status: 'pending' },
{ id: 2, status: 'approved' },
{ id: 3, status: 'rejected' }
]
};
},
methods: {
getSlotName(item) {
switch (item.status) {
case 'pending':
return 'pending-slot';
case 'approved':
return 'approved-slot';
case 'rejected':
return 'rejected-slot';
default:
return 'default-slot';
}
}
}
};
</script>
```
在上面的示例中,我们使用了一个`v-for`循环来遍历`items`数组,并为每个数组项动态选择插槽。根据`item.status`的值,我们使用`switch`语句来确定要使用的插槽名称。然后,我们在每个插槽中定义相应的内容。
请注意,这只是一个示例,你可以根据自己的业务需求进行修改和扩展。
阅读全文
相关推荐


















