Last active
March 17, 2021 15:36
-
-
Save sonidelav/f171b3d8aa460b607e858231c099ff67 to your computer and use it in GitHub Desktop.
I Promise a Modal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"> | |
<div class="modal-dialog modal-dialog-centered" role="document"> | |
<div class="modal-content"> | |
<div class="modal-header"> | |
<h5 class="modal-title">{{ title }}</h5> | |
</div> | |
<div class="modal-body"> | |
<p>{{ message }}</p> | |
</div> | |
<div class="modal-footer"> | |
<button type="button" class="btn btn-default" @click="cancel">No</button> | |
<button type="button" class="btn btn-primary" @click="ok">Yes</button> | |
</div> | |
</div> | |
</div> | |
</div> | |
</template> | |
<script> | |
import $ from 'jquery' | |
export default { | |
name: "PromisableBootstrapModal", | |
props: { | |
title: { required: true }, | |
message: { required: true } | |
}, | |
data: () => ({ | |
resolve: null | |
}), | |
methods: { | |
showModal() { | |
$(this.$el).modal('show'); | |
return new Promise((res) => { this.resolve = res; }) | |
}, | |
cancel() { | |
$(this.$el).modal('hide'); | |
this.resolve(false); | |
}, | |
ok() { | |
$(this.$el).modal('hide'); | |
this.resolve(true); | |
} | |
}, | |
beforeDestroy() { | |
$(this.$el).modal('dispose') | |
}, | |
mounted() { | |
$(this.$el).modal({ | |
backdrop: false, | |
focus: false, | |
show: false, | |
keyboard: false | |
}) | |
} | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<confirm-modal title="Are you sure?" message="Are you sure for this?" ref="confirmModal"/> | |
</template> | |
<script> | |
import ConfirmModal from './PromisableBootstrapModal' | |
export default { | |
name: 'App', | |
components: { ConfirmModal }, | |
async mounted() { | |
const { confirmModal } = this.$refs; | |
const result = await confirmModal.showModal(); | |
console.log(result); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment