TypeScript 错误 TS(18048): 解决 Canvas 宽度和高度未定义问题
这个错误是因为在使用 canvas 的宽度和高度之前,需要确保 canvas 已经有值。可以在使用 canvas 的宽度和高度之前,先进行判断,确认 canvas 已经有值,代码如下:
const canvas: Ref<HTMLCanvasElement | undefined> = ref();
if (canvas.value) {
config.ctx.clearRect(0, 0, canvas.value.width, canvas.value.height)
}
原文地址: https://www.cveoy.top/t/topic/oOK2 著作权归作者所有。请勿转载和采集!