<template>
{{ list }}
{{ filterList }}
<button @click="changeList">change list</button>
</template>
<script>
import { computed, ref } from 'vue'
export default {
setup() {
const list = ref([1, 2, 3, 4, 5, 6])
// 输入大于2的数字
const filterList = computed(() => {
return list.value.filter(item => item > 2)
})
// 修改list的函数
function changeList() {
list.value.push(6, 7, 8)
}
return {
list,
filterList,
changeList
}
}
}
</script>
vue3 computed 计算属性语法
最新推荐文章于 2024-09-14 12:05:57 发布