Vue.js 已声明Eslint状态[Vuex]
我正在运行ESLint,当前遇到以下ESLint错误: 错误“状态”已在上限范围中声明无阴影Vue.js 已声明Eslint状态[Vuex],vue.js,vuejs2,eslint,vuex,Vue.js,Vuejs2,Eslint,Vuex,我正在运行ESLint,当前遇到以下ESLint错误: 错误“状态”已在上限范围中声明无阴影 解决这个问题的最佳方法是什么?解决这个问题的最佳方法是阅读有关eslint“无阴影”规则的文档 从本文档中,最好的解决方案可能是使用“允许”选项包含此变量的例外情况 您可以将其与注释一起添加到js文件中,以使exeption保持本地: /* eslint no-shadow: ["error", { "allow": ["state"] }]*/ 最好的解决办法是 如果您正在寻找替代方案,则可以在剩余
解决这个问题的最佳方法是什么?解决这个问题的最佳方法是阅读有关eslint“无阴影”规则的文档 从本文档中,最好的解决方案可能是使用“允许”选项包含此变量的例外情况 您可以将其与注释一起添加到js文件中,以使exeption保持本地:
/* eslint no-shadow: ["error", { "allow": ["state"] }]*/
最好的解决办法是
如果您正在寻找替代方案,则可以在剩余值下方声明状态
常量。这将阻止,因为状态
尚未在外部范围中声明
例如:
const getters = {
date: state => state.date,
show: state => state.show
};
const mutations = {
updateDate(state, payload) {
state.date = payload.date;
},
showDatePicker(state) {
state.show = true;
}
};
const state = {
date: '',
show: false
};
export default {
state,
getters,
mutations
};
如果还不晚的话
const data = {
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: data,
getters,
mutations
};
基本上,您将存储数据定义为
data
,并将其导出为statestate:data
与我使用与vuex不兼容的airbnb eslint配置时遇到的问题相同
在重新启动dev环境后,这对我来说很有效
我在我的商店文件夹中创建了一个新的.eslintrc.js
文件,并将它们添加到那里
"no-shadow": ["error", { "allow": ["state"] }],
"no-param-reassign": [
"error",
{
"props": true,
"ignorePropertyModificationsFor": [ // All properties except state are in the ignorePropertyModificationsFor array by default.
"state",
"acc",
"e",
"ctx",
"req",
"request",
"res",
"response",
"$scope"
]
}
],
对于那些获得“no param reassign”错误的用户,这是解决方案:/*eslint no param reassign:[“error”,{“props”:true,“ignorePropertyModifications for”:[“state”]}]*/
"no-shadow": ["error", { "allow": ["state"] }],
"no-param-reassign": [
"error",
{
"props": true,
"ignorePropertyModificationsFor": [ // All properties except state are in the ignorePropertyModificationsFor array by default.
"state",
"acc",
"e",
"ctx",
"req",
"request",
"res",
"response",
"$scope"
]
}
],