计算属性就是当依赖的属性的值发生变化的时候,才会触发他的更改,如果依赖的值,不发生变化的时候,使用的是缓存中的属性值。
import {computed, ref} from 'vue'
let price = ref(0)
//函数形式
let newP = computed(() => {
return "¥" + price
})
//对象形式
let newP = computed({
get: () => {
return price.value
},
set: (value) => {
price.value = '¥' + value
}
})