用vue手脚架生成的项目直接修改时.vue文件后,保存编译就报一大堆的错,这是咋回事呢?

发布于 2022-09-03 19:23:21 字数 7993 浏览 17 评论 0

app.vue代码如下:

<template>
    <div id="app">
         <h1 v-text="title"></h1>
         <input v-model="newItem" @keyup.enter="addNew" />
         <ul>
             <li v-for="item in items" v-bind:class="{finished:item.isFinished}" v-on:click="toggleFinish(item)">
                 {{ item.label }}
             </li>
         </ul>
    </div>
</template>

<script>
export default {
  data () {
    return {
      title: 'vue to do list',
      items: [{
      label: 'aaa',
      isFinished: true
      },
       {
      label: 'bbb',
      isFinished: false
      }
      ],
      newItem: ''
    }
  },
  methods: {
                 toggleFinish: function(item){
          item.isFinished=!item.isFinished
      },
      addNew: function(){
          console.log(this.newItem); }
  }
}
</script>
<style>
.finished{
    color:#eee;
}
</style>

报错:

client.js?7955:105 [HMR] bundle has errors:
client.js?7955:107 [HMR] ./src/App.vue
  ✘  http://eslint.org/docs/rules/indent                       Expected indentation of 8 space characters but found 6                                                         
 /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:19:7
        label: 'aaa',
         ^
  ✘  http://eslint.org/docs/rules/indent                       Expected indentation of 8 space characters but found 6                                                         
/Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:20:7
        isFinished: true
         ^
  ✘  http://eslint.org/docs/rules/indent                       Expected indentation of 6 space characters but found 7                                                         
/Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:22:8
         {
          ^

  ✘  http://eslint.org/docs/rules/indent                       Expected indentation of 8 space characters but found 6                                                         
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:23:7
        label: 'bbb',
         ^

  ✘  http://eslint.org/docs/rules/indent                       Expected indentation of 8 space characters but found 6                                                         
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:24:7
        isFinished: false
         ^

  ✘  http://eslint.org/docs/rules/no-mixed-spaces-and-tabs     Mixed spaces and tabs                                                                                          
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:31:2
                   toggleFinish: function(item){
       ^

  ✘  http://eslint.org/docs/rules/indent                       Expected indentation of 4 space characters but found 1                                                         
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:31:6
                   toggleFinish: function(item){
                    ^

  ✘  http://eslint.org/docs/rules/space-before-function-paren  Missing space before function parentheses                                                                      
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:31:28
                   toggleFinish: function(item){
                                          ^

  ✘  http://eslint.org/docs/rules/space-before-blocks          Missing space before opening brace                                                                             
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:31:34
                   toggleFinish: function(item){
                                                ^

  ✘  http://eslint.org/docs/rules/no-mixed-spaces-and-tabs     Mixed spaces and tabs                                                                                          
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:32:2
            item.isFinished=!item.isFinished
    ^

  ✘  http://eslint.org/docs/rules/indent                       Expected indentation of 3 space characters but found 2                                                         
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:32:5
            item.isFinished=!item.isFinished
             ^

  ✘  http://eslint.org/docs/rules/space-infix-ops              Infix operators must be spaced                                                                                 
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:32:20
            item.isFinished=!item.isFinished
                            ^

  ✘  http://eslint.org/docs/rules/no-mixed-spaces-and-tabs     Mixed spaces and tabs                                                                                          
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:33:2
        },
    ^

  ✘  http://eslint.org/docs/rules/indent                       Expected indentation of 1 space character but found 2                                                          
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:33:4
        },
         ^

  ✘  http://eslint.org/docs/rules/no-mixed-spaces-and-tabs     Mixed spaces and tabs                                                                                          
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:34:2
        addNew: function(){
    ^

  ✘  http://eslint.org/docs/rules/indent                       Expected indentation of 4 space characters but found 2                                                         
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:34:4
        addNew: function(){
         ^

  ✘  http://eslint.org/docs/rules/space-before-function-paren  Missing space before function parentheses                                                                      
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:34:20
        addNew: function(){
                         ^

  ✘  http://eslint.org/docs/rules/space-before-blocks          Missing space before opening brace                                                                             
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:34:22
        addNew: function(){
                           ^

  ✘  http://eslint.org/docs/rules/no-mixed-spaces-and-tabs     Mixed spaces and tabs                                                                                          
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:35:2
            console.log(this.newItem); }
    ^

  ✘  http://eslint.org/docs/rules/brace-style                  Closing curly brace should be on the same line as opening curly brace or on the line after the previous block  
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:35:5
            console.log(this.newItem); }
             ^

  ✘  http://eslint.org/docs/rules/indent                       Expected indentation of 4 space characters but found 2                                                         
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:35:5
            console.log(this.newItem); }
             ^

  ✘  http://eslint.org/docs/rules/semi                         Extra semicolon                                                                                                
  /Users/apple/Desktop/VUEJS/vuePro/myvueProject01/src/App.vue:35:30
            console.log(this.newItem); }
                                      ^


✘ 22 problems (22 errors, 0 warnings)


Errors:
  10  http://eslint.org/docs/rules/indent
   5  http://eslint.org/docs/rules/no-mixed-spaces-and-tabs
   2  http://eslint.org/docs/rules/space-before-blocks
   2  http://eslint.org/docs/rules/space-before-function-paren
   1  http://eslint.org/docs/rules/semi
   1  http://eslint.org/docs/rules/brace-style
   1  http://eslint.org/docs/rules/space-infix-ops

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

七颜 2022-09-10 19:23:21

因为你设置了eslint,如果你不想有规范的js代码,可以重新初始化关掉eslint。
Use ESLint to lint your code? (Y/n) 这一步选no

如果你想有良好的规范,其实错误已经很清晰,大多数就是缩进不规范,分号不需要等原因,很容易解决的。写多了就成习惯了。

递刀给你 2022-09-10 19:23:21

在bulid/webpack.base.conf.js里面有配置如下:
module: {
rules: [

...(config.dev.useEslint ? [createLintingRule()] : []),

点进config.dev.useEslint,发现在config/index.js里配置
useEslint: true, // 改为false即可。

无需解释 2022-09-10 19:23:21

在vue-cli 创建的时候选择了ESLint规范就会这样,
可以先写,在保存,启动终端运行 npm run lint 使用ESLint自动修复即可
就是有点麻烦~~~~

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文