zoukankan      html  css  js  c++  java
  • vuex的四个参数 state mutations actions getters

    1.state(computed,  ...mapState

    用来保存数据的

    var state= { a:1 }

    2.mutations(methods,  ...mapMutations

    操控state里面的数据

    const mutations = {
        addAge(state) { state.a++ }
        reduceAge(state) { state.a-- }
    }

    3.actions(methods,  ...mapActions

    调用mutations里的方法,异步操作,可以对mutations里面的方法进行操作

    const actions = {
          addAgePro(obj) {
            console.log(obj)
          },
          reduceAgePro(obj) {
            console.log(obj)
          }
    }

    其中打印的obj的结构为

    commit: function, dispatch: function, getters: {}, rootGetters: {}, rootState: {__ob__:Observer}, state: {__ob__:Observer}

    4.getters(computed,  ...mapGetters

    相当于computed的作用,用于state数据的过滤操作

    const getters = {
        forlist(state) {
           return state.a += 1
        }
    }

     

  • 相关阅读:
    DC综合流程
    DC set_tcl脚本配置
    同步FIFO设计
    顺序脉冲 发生器
    状态机的写法
    verilog串并转换
    indexOf()
    jQuery 效果
    jQuery 事件
    jQuery css
  • 原文地址:https://www.cnblogs.com/pwindy/p/15543845.html
Copyright © 2011-2022 走看看