0👍
Assuming that your form fields are using v-model
or similar bindings with vue (as they should so you can leverage from Vue’s features), you can remove the @submit
event on the form
html tag and let vue handle the click event on the button.
<form>
<input type="text" v-model="user.firtName"/>
... (generic form code)
<button v-show="editmode" type="button" class="btn btn-success" @click="editmode ? updateUser() : createUser()">update</button>
</form>
Note that the type
is now button instead of submit. After the updateUser
or createUser
are done doing their thing, just emit an event from the modal to the parent component to dismiss the modal.
updateUser(){
this.$Progress.start()
// Use Axios HERE, something like
axios.put(base_path+'/admin_api/user/'+this.form.id, this.user)
.then(()=>{
// ...
})
.catch(()=>{
this.$Progress.fail()
})
.finally(() => {
this.$emit('closeModal');
})
}
- [Vuejs]-How to include external JavaScript library properly so that its class is avialable in VueJs component?
- [Vuejs]-@change method is taking the previeous selected value of select box
Source:stackexchange.com