1.vue3组合式api中怎么使用计算属性
import { ref, computed } from 'vue'
const num1 = ref(1)
const num2 = ref(2)
const sum = computed(() => num1.value + num2.value)
// computed 返回的是一个ref
2.为 computed() 标注类型
import { ref, computed } from 'vue'
const num1 = ref(1)
const num2 = ref(2)
const sum = computed<number>(() => num1.value + num2.value)
3.创建一个可写的计算属性
import { ref, computed } from 'vue'
const num = ref(1)
const sum = computed({
get: () => num.value + 1,
set: (val) => {
num.value = val -1
}
})