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) } }