vue.js – Vuex:为什么我们用大写写突变,动作和getter?

前端之家收集整理的这篇文章主要介绍了vue.js – Vuex:为什么我们用大写写突变,动作和getter?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想知道为什么我们用大写字母编写突变,动作和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

原文链接:https://www.f2er.com/js/150989.html

猜你在找的JavaScript相关文章