Eslint状态已声明[Vuex] [英] Eslint state already declared [Vuex]

查看:74
本文介绍了Eslint状态已声明[Vuex]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行ESLint,当前正在遇到以下ESLint错误:

I am running ESLint and I am currently running into the following ESLint error:

错误状态"已在较高范围的无阴影状态中声明

error 'state' is already declared in the upper scope no-shadow

const state = {
    date: '',
    show: false
};

const getters = {
    date: state => state.date,
    show: state => state.show
};

const mutations = {
    updateDate(state, payload) {
        state.date = payload.date;
    },
    showDatePicker(state) {
        state.show = true;
    }
};

export default {
    state,
    getters,
    mutations
};

解决此问题的最佳方法是什么?

What would be the best way to fix this?

推荐答案

最好的解决方法是阅读有关eslint无阴影"规则的文档.

The best way to fix would be to read the docs about the eslint "no-shadow" rule.

根据本文档,最好的解决方案可能是使用"allow"选项为该变量添加一个例外.

From this documentation, the best solution would probably be to include an exception for this one variable with the "allow" option.

您可以在js文件中添加带有注释的内容,以使exeption保持本地状态:

You can add this with a comment to the js file to keep the exeption local:

/* eslint no-shadow: ["error", { "allow": ["state"] }]*/

这篇关于Eslint状态已声明[Vuex]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆