
获得徽章 0
- 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);
}
};
修改成一下代码时问题解决了,但鼠标事件不生效了展开赞过143 - #1024一起掘金# nvm use 切换版本提示成功,但通过nvm ls查看的时候,还是在原先的老版本上, 是因为我的nvm版本高(当前版本v1.1.11,最低只能找到node v16.18.1),不支持node低版本(v12.13.0)吗。我安装nvm前把node都卸载,环境变量也删了等人赞过44