Vue3中计算属性computed的基本概念 官网
在Vue3里,计算属性computed是很实用的功能。它能根据已有数据算出新数据,避免在模板里写复杂表达式。 计算属性本质是函数,但用起来像数据。例如: {{msg}} {{rmsg}} script setupimport {computed,ref} from 'vue'const msg = ref("你好中国")const rmsg = computed(()=>{ return msg.value.split('').reverse().join(''); // 运行结果 "国中好你"})/script 注意计算属性是基于依赖进行缓存的,只有依赖数据变化,计算属性才重新计算。