美文网首页
vuex辅助函数

vuex辅助函数

作者: vzii | 来源:发表于2019-12-06 10:39 被阅读0次

1.取state的值(mapState)

1.import { mapState } from 'vuex'

2. computed: {

    ...mapState({

      foodData: state => state.food_list,

      table: state => state.table,

      user: state => state.user

    })

}

3.this.table

2.保存值(mapMutations )

注:setTable: (state, table) => {

      state.table = table

    },

1.import { mapMutations } from 'vuex'

2.methods: {

    ...mapMutations([

      'setTable'

    ]),

}

3.this.setTable //无需定义

3.actions里面写事件(mapActions)

注:logOut ({ commit }) {

      return new Promise((resolve) => {

        this._vm.$post('/storeapp/login/loginout').then((res) => {

          commit('foodList', '')

          commit('setUser', '')

          resolve()

        }).catch(() => {

          commit('foodList', '')

          commit('setUser', '')

        })

      })

    }

1.import { mapActions } from 'vuex'

2.methods: {

    ...mapActions({

      logOutAction: 'logOut'

    }),

}

3.this.logOutAction()

相关文章

网友评论

      本文标题:vuex辅助函数

      本文链接:https://www.haomeiwen.com/subject/lbvsgctx.html