无法禁用模板中的eslint-plug-vue错误[vue / no-use-v-if-with-v-for]

时间:2019-06-17 18:16:22

标签: vue.js vuejs2 eslint eslint-plugin-vue

我尝试了很多次,但是都没有结果。编译成功,但始终出现以下错误:

  

[vue / no-use-v-if-with-v-for]   'v-for'指令内的'allOptions'变量应替换为返回过滤数组的计算属性。您不应将“ v-for”与“ v-if”混合使用。 eslint-plugin-vue

我知道不建议同时使用这些指令,即使主要文档也提供了类似的示例 (v-for with v-if):

<li v-for="todo in todos" v-if="!todo.isComplete">
    {{ todo }}
</li>

禁用评论无效:

<!-- eslint-disable-->
<h5 v-for="(option, index) in allOptions" :key="index" v-if="option == 'something'">{{option}}</h5>
<!-- eslint-enable -->

我也尝试过:

<!-- eslint-disable-next-line vue/no-use-v-if-with-v-for -->
<h5 v-for="(option, index) in allOptions" :key="index" v-if="option == 'something'">{{option}}</h5>

并尝试添加具有以下内容的 .eslintrc 文件:

{
    "rules": {
        "vue/no-use-v-if-with-v-for": ["error", {
            "allowUsingIterationVar": true
        }]
    }
}

我不知道如果eslint似乎没有作为模块安装( package.json

,该如何工作?
{
    "name": "dynamicfiltring",
    "description": "A Vue.js project",
    "version": "1.0.0",
    "author": "13thKID <kid.want2saybang@gmail.com>",
    "license": "MIT",
    "private": true,
    "scripts": {
        "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
        "build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
    },
    "dependencies": {
        "vue": "^2.5.11",
        "vue-i18n": "^8.11.2",
        "vuex": "^3.1.1"
    },
    "browserslist": [
        "> 1%",
        "last 2 versions",
        "not ie <= 8"
    ],
    "devDependencies": {
        "babel-core": "^6.26.0",
        "babel-loader": "^7.1.2",
        "babel-plugin-transform-runtime": "^6.23.0",
        "babel-preset-env": "^1.6.0",
        "babel-preset-stage-3": "^6.24.1",
        "cross-env": "^5.0.5",
        "css-loader": "^0.28.7",
        "file-loader": "^1.1.4",
        "node-sass": "^4.5.3",
        "sass-loader": "^6.0.6",
        "vue-loader": "^13.0.5",
        "vue-template-compiler": "^2.4.4",
        "webpack": "^3.6.0",
        "webpack-dev-server": "^2.9.1"
    }
}

0 个答案:

没有答案