首页 > 解决方案 > 如何使用意外令牌解决 ESLint 错误?

问题描述

我正在使用 Vue/TS 应用程序来读取 JSON 并比较它们。但我有一个 linter 错误。

这是错误:

319:33 错误解析错误:意外的令牌。你是说{'>'}还是>

第 319:33 行是我在下面的代码中检查文件长度的行:

handleFileInput(e:Event) {
      const target:HTMLInputElement = <HTMLInputElement>e.target
      const id:string = target?.id
      console.log(id)
      const files:FileList|null = target.files
      if (files && files?.length > 0) {
        const file = files[0]
        const reader = new FileReader()
        reader.onload = () => {
          const res = JSON.parse(<string>reader.result)
          if (id === "fileBr") {
            this.br.json = res
            this.br.name = file.name
          } else if (id === 'fileC') {
            this.c.json = res
            this.c.name = file.name
          }
        }
        reader.readAsText(file)
      }
    },

有人知道 es-lint 是否存在代码问题或配置错误?

谢谢

标签: typescriptvue.jseslint

解决方案


我刚刚发现!

我应该使用: reader.result 作为字符串而不是 reader.result

这就是为什么我有意想不到的令牌


推荐阅读