在将Eslint添加到我的项目中之后,我在我的应用程序中遇到了这个错误.模板部件中的vue文件

Parsing error: '>' expected.eslint

在这个代码块中

<template>
  <div class="flex justify-center h-40">
    <div class="bg-blue-500 w-40 h-full"></div>
  </div>
</template>

Basically, adding an attribute to any HTML tag throws this error

I'm using a Vue 3 with the "vue-ts" Vite template.
VSCode is my editor and i'm obviously the ESlint plugin :)
Here is my .eslintrc configuration

module.exports = {
  'env': {
    'node': true,
  },
  'extends': [
    'eslint:recommended',
    'plugin:vue/base',
    'plugin:vue/vue3-recommended',
    'plugin:@typescript-eslint/recommended'
  ],
  'parserOptions': {
    'ecmaVersion': 12,
    'parser': '@typescript-eslint/parser',
    'sourceType': 'module'
  },
  'plugins': [
    'vue',
    '@typescript-eslint'
  ],
  'rules': {
    'indent': [
      'error',
      'tab'
    ],
    'linebreak-style': [
      'error',
      'unix'
    ],
    'quotes': [
      'error',
      'single'
    ],
    'semi': [
      'error',
      'never'
    ]
  }
}

谢谢

推荐答案

您尚未在eslint配置中设置parser选项.从documentation人中:

默认情况下,ESLint使用Espree作为其解析器.[…]要指示要用作解析器的npm模块,请在.eslintrc文件中使用parser选项指定它.

使用vue-eslint-parser来删除.vue个文件中的<template>个:

{
  "parser": "vue-eslint-parser"
}

Vue.js相关问答推荐

如何只提取一次用于无线电组过滤的数据,而不是针对数据库中的每个条目提取数据?

为什么 Pinia/Vuex 比使用服务类的classic 方法更受欢迎?

Vuetify 扩展面板,面板标题左侧带有图标

Vue:在表格中显示嵌套数据

在按键 vuejs 中只允许数字和一个小数点后 2 位限制

是否可以在没有 Vue 的情况下使用 Vuex?

VueJS 将 HTML 打印到页面

NuxtServerInit 在 Vuex 模块模式下不起作用 - Nuxt.js

Vuetify - 根据另一个 Select 选项过滤 Select 数据

Vue 3 组合 API,如何在 setup() 函数中获取上下文父属性?

执行调度程序刷新期间未处理的错误,这可能是一个 Vue 内部错误

如何从 keep-alive 中销毁缓存的 Vue 组件?

vue-router如何持久化导航栏?

Vuejs获取事件正在调用的元素?

如何使用 Vue Test utils 测试输入是否聚焦?

VS Code - 在 .vue 文件中启用 autoClosingTags 选项

VueJS 2 + ASP.NET MVC 5

如何在布局中使用组件?

将鼠标悬停在 TailwindCSS 中的 div 上时显示按钮

Vue-meta:metaInfo 无权访问计算(computed)属性