学习要点:
1.computed
本节课我们来要了解一下 Vue3.x 中的计算属性 computed 用法;
一.computed
1. computed 是组合式 API 中的计算属性的功能,和传统式基本一致;
const count = ref(1)
//const myCount = computed(() => count.value)
const myCount = computed(() => {
return count.value
})
// getter,setter
const yourCount = computed({
get : () => 'count:' + count.value,
set : (val) => {
count.value = val
}
})
yourCount.value = 10
return {
myCount,
yourCount
}