vue3 computed传参数
时间: 2024-01-18 13:18:31 浏览: 114
在Vue3中,computed计算属性可以传递参数。以下是两种在Vue3中使用computed传递参数的例子:
1. 在v-for中使用计算属性传参:
```html
<div v-for="item in list">
<div v-if="isShow(item)">是否显示</div>
</div>
<script>
import { computed, ref } from 'vue'
const currentId = ref(null)
const isShow = computed(() => (item) => {
// 计算属性传递参数
return currentId.value === item.id
})
</script>
```
2. 在slot插槽中计算属性传参:
```html
<ss-vue-calendar>
<template #tbodyCell="scope">
<span v-if="getCurrentDayDetailed(scope.item)">
{{ getCurrentDayDetailed(scope.item) }}
</span>
</template>
</ss-vue-calendar>
<script lang="ts">
import { computed } from 'vue'
const getCurrentDayDetailed = computed(() => (item) => {
return item.id === '123'
})
</script>
```
阅读全文
相关推荐


















