how to validate and reset value in watch?
Version
3.2.31
Reproduction link
Steps to reproduce
if value is object, i want it can use v-model, because computed attr change can not trigger set, i need to use watch
to listen the attr change, but user`s some input is valid , i need to reset the value, when i use like this, can not work normally.
interface Props {
item: Record<string, unknown>;
modelValue: {
condition: string;
value: unknown;
};
}
const props = defineProps<Props>();
const emit = defineEmits(['update:modelValue']);
const field = toRef(props, 'modelValue');
watch(
() => field.value,
val => {
const data = cloneDeep(val);
const value = data.value;
if (Array.isArray(value)) {
data.value = value.filter(elem => elem !== null);
}
emit('update:modelValue', data);
},
{
deep: true
}
);
What is expected?
work normally
What is actually happening?
Maximum recursive updates exceeded in component
The Jack can't selected. Example
The Jack can't selected. Example
This is my mistake. i reset it need a condition.