在使用vue cli3的时候,遇到如下问题:

error: Parsing error: Unexpected token < at src\views\index.vue:1:1:
> 1 | <template>
    | ^
|   <div class="index">
|     <router-view></router-view>
|     <TabBar :data="tabbarData"></TabBar>

  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

查阅了许多网站,都不能解决此问题,最后,在

https://stackoverflow.com/questions/53601579/parsing-error-unexpected-token-using-vuecli3-and-airbnb-eslint?r=SearchResults

找到了办法

打开你的 .eslintrc.js 文件,找到 parser

这是我的 .eslintrc.js

module.exports = {
    rules: {
        'no-console': 'off',
        "parser": "vue-eslint-parser"
    },
}

  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

注意:

当我写入 import 时,就会报上述错误,这个时候,只需要把 .eslintrc.js 里的

“parser”: “vue-eslint-parser” 注释掉,重新启动项目。然后,取消掉注释,再次重启项目,就没有报错了。

为什么会这样,我也不理解。如果你们有了更好的解决办法,麻烦给我留言,谢谢!!!

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐