首页 > 其他 > 详细

vuex中action中发送数据

时间:2020-05-12 00:25:32      阅读:77      评论:0      收藏:0      [点我收藏+]
state: {
    actionData: "",
},

mutations: {
    actioncomAPi: (state, data) => {
      state.actionData = data; //赋值
    },
}

 //异步
actions: {
    actionDataApi(context) {
      axios.get("http://127.0.0.1:667/account").then((res) => {
        context.commit("actioncomAPi", res); //通过commit来设置值
        console.log("在action中设置值", res);
      });
    },
  },

调用页面

created() {
        this.MyCHufa();
    },

methods:{
       MyCHufa() {
            this.$store.dispatch(‘actionDataApi‘);//触发action中的方法
            console.log(this.$store.state.actionData)
        }
}
      

vuex中action中发送数据

原文:https://www.cnblogs.com/IwishIcould/p/12873095.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!