Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vuex状态管理 #5

Open
Alexandermclean opened this issue Mar 16, 2019 · 0 comments
Open

vuex状态管理 #5

Alexandermclean opened this issue Mar 16, 2019 · 0 comments

Comments

@Alexandermclean
Copy link
Owner

针对这次项目,有个直观的感受就是:数据在组件间通信比较频繁的情况下,通常用的父子组件、兄弟组件通信方式就会显得异常繁琐,而且不便于管理。
从VUE一个简单的状态自管理应用来看:

new Vue({
  // state
  data () {
    return {
      count: 0
    }
  },
  // view
  template:
    <div>{{ count }}</div>

  // actions
  methods: {
    increment () {
      this.count++
    }
  }
})

这个状态自管理应用包含以下几个部分:

  • state:驱动应用的数据源;
  • view:以声明方式将state映射到视图;
  • actions:响应在 view上的用户输入导致的状态变化。

这是一个普通的组件从样式渲染到数据绑定再到数据变化,单一的状态比较清晰,遇到多个组件共享状态时,这种简洁性很容易被破坏且难以管理。因此,把组件的共享状态抽出来,以一个全局单例模式管理,这就是VUEX背后的基本思想。

vuex

@Alexandermclean Alexandermclean added this to Vue in Vue Mar 16, 2019
@Alexandermclean Alexandermclean added the Vue Vue label Mar 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Vue Vue
Projects
Vue
  
Vue
Development

No branches or pull requests

1 participant