zoukankan      html  css  js  c++  java
  • vuex的commit

    const store = new Vuex.Store({
      state: {
        count: 0
      },
      mutations: {
        increment (state) {
          state.count++
        }
      },
      actions: {
        increment (context) {
          context.commit('increment')
        }
      }
    })

    store 中的状态的唯一方法是提交 mutation 

    store.commit('increment')

    ----------------------------------------------------------

    Action 函数接受一个与 store 实例具有相同方法和属性的 context 对象,因此你可以调用 context.commit 提交一个 mutation [context 对象不是 store 实例本身了]

    actions: {
      increment ({ commit }) {
        commit('increment')
      }
    }

    ----------------------------------------------------------

    this.$store.dispatch() 与 this.$store.commit()方法的区别总的来说他们只是存取方式的不同,两个方法都是传值给vuex的mutation改变state


    this.$store.dispatch() :含有异步操作,例如向后台提交数据,写法:this.$store.dispatch(‘action方法名’,值)


    this.$store.commit():同步操作,例如向后台提交数据,写法:this.$store.commit(‘mutations方法名’,值)

    commit: 同步操作

    存储 this.$store.commit('changeValue',name)
    取值 this.$store.state.changeValue


    dispatch: 异步操作

    存储 this.$store.dispatch('getlists',name)
    取值 this.$store.getters.getlists


    存储一样 取值方式不同罢啦

    转 :  https://blog.csdn.net/u011565547/article/details/108830084

  • 相关阅读:
    Qt环境搭建(Visual Studio)
    HTML基础
    关于Qt
    I am back
    Node Security
    Mobile Assistant
    Home Server
    抉择-什么最重要
    在一个JSP页面中包含另一个JSP页面的三种方式
    JS控制DIV隐藏显示
  • 原文地址:https://www.cnblogs.com/fps2tao/p/15196084.html
Copyright © 2011-2022 走看看