vue3+ts 遇到个问题,想问下各位大佬这个问题该怎么处理呢。需求是我鼠标移入到四个div中间时需要进行一系列判断,通过ref去获取对应的dom后,el一直报类型错误。
报错内容:类型“Element | ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null”的参数不能赋给类型“HTMLDivElement | null”的参数。ts-plugin(2345)
修改类型代码:
const setColRef = (el: Element | ComponentPublicInstance | null, index: number) => {
// Ensure the element is an HTMLDivElement or a Vue component instance
if (el instanceof Element) {
colRefs.value[index] = el;
} else if (el && '$el' in el) {
colRefs.value[index] = (el.$el as Element);
}
};

修改成一下代码时问题解决了,但鼠标事件不生效了
展开
莫问style于2024-06-24 09:50发布的图片
莫问style于2024-06-24 09:50发布的图片
莫问style于2024-06-24 09:50发布的图片
14