我正在运行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
};
解决这个问题的最佳方法是什么?
解决方法
解决问题的最佳方法是阅读有关“无阴影”规则的文件.
从这个文档中,最好的解决方案可能是使用“allow”选项为这一个变量包含一个例外.
您可以在js文件中添加注释以使exeption保持为本地:
/* eslint no-shadow: ["error",{ "allow": ["state"] }]*/