Answer the question
In order to leave comments, you need to log in
Why is the Vue custom event not firing in the then block?
I want to make a request to the server on a button click, and when a response is received, trigger a custom event and pass it to the parent component:
onAddWordSubmit(){
this.$emit('change-state', 'loading');
this.axios.post('http://127.0.0.1:8000/api/v1.0/word/create/', {
'word': this.word,
'translate': this.translate,
'context': this.context
})
.then(()=>{
this.$emit('change-state', 'wordarea');
});
Answer the question
In order to leave comments, you need to log in
You use a dynamic component, initially you render a wordarea, when you send a request you switch the dynamic component to another one, at this moment your wordarea component is destroyed and a loading component is created in its place, and accordingly, after the wordarea is destroyed, all signed events are unbind and in fact you are trying get the 'change-state' event already at the loading component
You can try to wrap it in keep-alive and the components will not be deleted when switching
<keep-alive>
<component
v-bind:is="currentComponent"
v-on:change-state="changeState($event)">
</component>
<keep-alive>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question