gpt4 book ai didi

vue.js - Eslint 状态已经声明 [Vuex]

转载 作者:搜寻专家 更新时间:2023-10-30 22:09:44 24 4
gpt4 key购买 nike

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

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
};

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

最佳答案

最好的修复方法是阅读有关 eslint“no-shadow”规则的文档。

根据该文档,最好的解决方案可能是使用“允许”选项为这个变量包含一个异常(exception)。

您可以将其添加到 js 文件中并添加注释以将异常保留在本地:

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

关于vue.js - Eslint 状态已经声明 [Vuex],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43843180/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com