关于Vuex的actions传入多个参数的方法:

  1.在state中:
            state={
       obj:{
         name:'state中的数据'
     }
  }
        2.在actions定义的方法中:
            getStateData(context, value) {
           context.commit("getStateData", value);
      }
        3.在mutations定义的方法中:
            getStateData: (state, obj) => {
            console.log(state);   //{{name:'state中的数据'}}
            console.log(obj);    //{ name: "张老三", age: "80岁" }
   }
          4. 在组件中传参数:
            methods: {
            method1() {
            this.$store.dispatch("getStateData", { name: "张老三", age: "80岁" });  //将参数以对象的形式写入
         }
     }

猜你喜欢

转载自www.cnblogs.com/shidawang/p/12090971.html