I have a click function in the methods of a child component
takehash(index){
let hash = this.searchList[index].hash;
this.$store.commit('playvideo', hash);
console.log(this.$store.state.box.Url);
}
There is a method in the mutations of store
playvideo(state,hash){
Vue.http.get("json.php"+hash).then(res=> {
let jsonObj = res.data;
state.box.Url= jsonObj.url;
console.log('no');
});
}
But I found that the process I wanted was to commit the playvideo method, and after executing the playvideo method, the console came out with its url.
But the result was that the url was consoled first, and then the playvideo method was executed. Mutations are not a synchronous method. ?, why is the execution delayed? I am new to vuex, please ask someone to solve it
Theoretically, mutations are only used to put synchronous methods. They cannot use asynchronous methods.
And if you put an asynchronous method in your playvideo.
Then the execution result must be asynchronous.
Synchronization of mutations means that you have to ensure that the methods in mutations are synchronous, not mutations that turn your asynchronous methods into synchronization.
Asynchronous methods are placed in actions