<script setup lang="ts">
import { ref, computed } from 'vue'
type Tlist = {
id: number
name: string
done: boolean
}
const list = ref<Tlist[]>([
{ id: 1, name: 'chifan1', done: false },
{ id: 11, name: 'chifan11', done: false },
{ id: 111, name: 'chifan111', done: true }
])
//计算属性,不需要自动指类型,他会自己类型推断
const doneTrue1 = computed(() => {
return list.value.filter((it) => it.done)
})
//也可以自己加类型
const doneTrue2 = computed<Tlist[]>(() => {
return list.value.filter((it) => it.done)
})
</script>
<template>
<h1>1</h1>
<h3>2</h3>
</template>
<style scoped></style>
ift
TS 计算属性computed,不需要自动指类型,他会自己类型推断
最新推荐文章于 2024-05-23 22:02:27 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)