我在Vuejs项目上运行了Airbnb Eslint次(使用Vue cli).其中一条规则是no-param-reassign.使用Vuex(必须/必须)来控制状态:
Rules conflict
mutations: {
increase: (state) => {
state.counter++;
}
}
After changes according to rules
mutations: {
increase: (state) => {
const thisState = state;
thisState.coutner++;
}
}
有没有更好的方法来写上面的陈述而不违反eslint规则?
Solution (thanks to 100's 101)
在规则的ignorePropertyModificationsFor
处加'state'
.