vue3+ts:el.scrollHeight 提示类型“never”上不存在属性“scrollHeight”。

重点: const el = textRefs.value[index] as HTMLElement;或者将textRefs 写作const textRefs = ref<HTMLElement[]>([]);

	const textRefs = ref<HTMLElement[]>([]);
	const overflowStates = reactive<boolean[]>([]);
	// 检测文本溢出
	const checkOverflow = (event: any, index: number) => {
		nextTick(() => {
			const el = textRefs.value[index];

			if (el) {
				// 比较实际高度与可视高度
				overflowStates[index] = el.scrollHeight > el.clientHeight;
			}
		});
	};

更多推荐