将参数存到store并从中拿出来的方法

页面中要将数据存到vuex 中的方法

this.$store.commit("print/setPrint", { ID: this.ID, BrandID: 46 });

【将参数存到store并从中拿出来的方法】Store的写法
// initial state const state = { all: { ID:'', BrandID:'' } }// getters const getters = {}// actions const actions = { // getAllPurchasedTools ({ commit }) { //purchasedTools.getPurchasedTools((tools) => { //commit('setPurchasedTools',tools) //},state.params); // } }// mutations const mutations = { setPrint(state, all) { //设置参数 state.all = all; } }export default { namespaced: true, state, getters, actions, mutations }

然后在store下面的index.js文件中
import print from './module/print'; export default new Vuex.Store({ modules: { print }, strict: debug,//开启严格模式 plugins: debug ? [createLogger()] : [] })

用到的页面
import { mapState, mapActions } from "vuex"; computed: { ...mapState({ print:state=>state.print.all }) }

在用到的地方直接this点出来即可
this.CreateUserID = this.print.ID; this.GoodsID = this.print.BrandID;

    推荐阅读