我想知道为什么我们用大写字母编写突变,动作和getter的函数名?这个惯例来自哪里?
export default { SOME_MUTATION (state,payload) { },ANOTHER_MUTATION (state,}
解决方法
以全部大写形式写出常量是一个
long standing coding style.
来自Vuex documentation:
It is a commonly seen pattern to use constants for mutation types in
varIoUs Flux implementations. This allows the code to take advantage
of tooling like linters,and putting all constants in a single file
allows your collaborators to get an at-a-glance view of what mutations
are possible in the entire application
因此,它实际上只是遵循了大部分命名常量大写的长期传统.这不是必需的.
Whether to use constants is largely a preference – it can be helpful in large projects with many developers,but it’s totally optional if you don’t like them