Computed
vue3中的computed
get()和set()方法时,读和写该变量时执行的。而不是依赖props?.policyInfo?.insureType变化了去执行的。
const isSheBao = computed({
get: () => props?.policyInfo?.insureType === INSURE_TYPES.SHEBAO, // 用isSheBao的时候执行执行get。
set: (val) => { // 给isSheBao.value=xx赋值时 写操作时执行set。
console.log(val);
setPayeeListOptions(val);
}
});
console.log(isSheBao.value) // 读,走get方法。
isSheBao.value = false; // 写,只有isSheBao.value,必须本身发生变化时,才去走set。