如何解决未处理的运行时错误 - TypeError:无法读取未定义的属性“长度”(Nextjs)? 我在开发过程中遇到了未处理的运行时错误 - TypeError: Cannot read property "length" of undefined (Nextjs)。 如何解决问题?下面主要结合日常开发经验,给大家提供未处理的运行时错误的解决方案建议——TypeError: Unable to read undefined property "length" (Nextjs)。 我希望它可以帮助您解决未处理的运行时错误 - TypeError: Cannot read property 'length' of undefined (Nextjs) 任何灵感或帮助; 问题描述
我正在编写代码来接受二维码图像并将其解码为字符串。
这些图像将是 Nextjs 文件夹“public”中的静态文件。
在我的代码中javascript运行时错误 未定义,我已将图像转换为“imageData”。 我成功转换并获得了一个返回 Uint8ClampedArray 的“imageData”对象。
然后,我使用这个 npm 库制作了一个 javascript 二维码阅读器。
但是,不知怎的javascript运行时错误 未定义,它给了我这个错误。
未处理的运行时错误 TypeError:无法读取未定义的属性“长度”
这是我的 localhost:3000 中显示的错误
当我查看我的代码编辑器时。 我在第 372 行有突出显示。
不过,我觉得 .next 库中的第 372 行是我不应该做的事情。
这可能就是我的代码。
这是我的代码。
索引.js
import Head from 'next/head'
import styles from '../styles/Home.module.css'
import jsQR from 'jsqr'
import { useEffect } from 'react'
export default function Home() {
useEffect(() => {
const canvas = document.getElementById("canvas");
const ctx = canvas.getcontext('2d');
const width = 200;
const height = 200;
const image = new Image;
var imageDataT
image.src = './Test_QR_Coupon.png'
image.onload = () => {
ctx.drawImage(image,width,height);
imageDataT = ctx.getImageData(0,200,200);
console.log(imageDataT);
}
const code = jsQR(imageDataT,300,'dontInvert')
console.log('Code:',code)
if (code) {
console.log("Found QR code",code);
}
})
return (
<div classname={styles.container}>
Create Next App
<main classname={styles.main}>
<footer classname={styles.footer}>
Powered by{' '}
sname={styles.logo} />