一、computed计算属性函数
![](https://img.haomeiwen.com/i27493437/8870fd8a17ea3dcb.png)
![](https://img.haomeiwen.com/i27493437/5bbc276721d1e778.png)
<script setup>
import { computed, ref } from "vue";
// 声明数据
const list = ref([1, 2, 3, 4, 5, 6, 7, 8]);
// 基于list派生一个计算属性,从list中过滤出 > 2
const computedList = list.value.filter((item) => item > 2);
</script>
<template>
<h1>原list:{{ list }}</h1>
<h1>计算属性list:{{ computedList }}</h1>
</template>
![](https://img.haomeiwen.com/i27493437/5528fac97339a134.png)
二、计算属性的最佳实践
![](https://img.haomeiwen.com/i27493437/be25f3c943c48deb.png)
网友评论