My vue component like this :
<template>
<div ref="modal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form>
...
<div class="modal-footer">
...
<button type="button" class="btn btn-success" @click="addPhoto">
Save
</button>
</div>
</form>
</div>
</div>
</div>
</template>
<script>
export default {
...
methods: {
addPhoto() {
const data = { id_product: this.idProduct };
this.$store.dispatch('addImageProduct', data)
.then((response) => {
this.$parent.$options.methods.createImage(response)
});
},
}
}
</script>
If I click button addPhoto, it will call addPhoto method.
addPhoto method used to call ajax. After response of ajax, it will pass the response to createImage method in parent component
After run it, the modal not close. Should the modal close after click save button
How can I close the modal after call createImage method?
You cannot use Bootstrap and Vue together this way. Each wants to control the DOM, and they will step on each others' toes. To use them together, you need wrapper components so that Bootstrap can control the DOM inside the component and Vue can talk to the wrapper.
Fortunately, there is a project that has made wrapper components for Bootstrap widgets. It is Bootstrap-Vue. Its modal will automatically close when you press its ok button. I have turned their modal example into something that is vaguely like what you're trying to do.
if i understand what you want then, add this data-dismiss="modal" to whichever button you want to use for closing the modal.. suppose you have a button Upload Image on clicking which you want to upload the image as well as close the modal then add data-dismiss="modal" to the button property like i have shown above...