在 Vue 3 中,如果你使用 reactive 创建响应式对象,然后在 computed 中使用这些响应式对象,确实可能会出现计算属性不会实时更新的情况。这是因为 computed 默认情况下只会在它所依赖的响应式变量被访问时才会重新计算,而不会在这些变量的内部值发生改变时触发重新计算。
let curPaper=ref({type: 'other',width: 210,height: 296.6
});
const curPaperType = computed(() => {debuggerlet type = 'other';let types = paperTypes;for (const key in types) {let item = types[key];let { width, height } = curPaper.value;if (item.width === width && item.height === height) {type = key;}}return type;
});