Troubleshooting while using defineModel #12674
Answered
by
Wei-Ba
gio-hernandez-saito
asked this question in
Help/Questions
-
Hello, I'm currently trying to make some visualization component. Below are some codes... interface HTopoMapProps extends HVizMargin {
topoData: any;
mapRegionData: any;
prefix: string;
suffix: string;
colorRange: [string, string];
}
const props = withDefaults(defineProps<HTopoMapProps>(), {
top: 20,
bottom: 20,
left: 20,
right: 20
})
const highlightTarget = defineModel<string|undefined>('highlightTarget')
onMounted(() => {
init()
update()
})
watchDebounced(props, (v) => {
console.log(v) // why props is triggerred!!!
update();
}, { debounce: 100 })
// draw is called inside update
function draw() {
// ...
svg.on('mouseenter', function(_, d) {
// ...
highlightTarget.value = d.id
})
// mouseleave too
} What is quite interesting is that when I trigger 'mouseenter', 'mouseleave' event, watchDebounced is called again.
And, also I tried to omit two properties... const excludedProps = computed(() => omit(props, ['highlightTarget', 'highlightTargetModifiers'])) // lodash omit But watchDebounced(excludedProps) still called.... How can I solve this problem?
|
Beta Was this translation helpful? Give feedback.
Answered by
Wei-Ba
Jan 9, 2025
Replies: 1 comment 3 replies
-
const excludedProps = reactive(omit(toRefs(props), ['highlightTarget', 'highlightTargetModifiers']))
watch(excludedProps, ...) |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
gio-hernandez-saito
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
defineModel