Skip to content

Commit

Permalink
refactor: refine Collapse logic
Browse files Browse the repository at this point in the history
  • Loading branch information
wxsms committed Nov 22, 2021
1 parent 5b39e02 commit 7525bc7
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/components/collapse/Collapse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ export default defineComponent({
let timeoutId = 0;
const element = ref(null);
function toggle(show) {
clearTimeout(timeoutId);
function toggle() {
const show = props.modelValue;
const el = element.value;
// console.log('toggle', el, show);
clearTimeout(timeoutId);
if (!el) {
return;
}
Expand Down Expand Up @@ -57,18 +59,10 @@ export default defineComponent({
}
}
watchEffect(() => {
toggle(props.modelValue);
});
onMounted(() => {
addClass(element.value, COLLAPSE);
if (props.modelValue) {
addClass(element.value, IN);
}
});
watchEffect(toggle);
return () => h(props.tag, { ref: element }, slots.default?.());
return () =>
h(props.tag, { ref: element, class: COLLAPSE }, slots.default?.());
},
});
</script>

0 comments on commit 7525bc7

Please sign in to comment.