Skip to content

Instantly share code, notes, and snippets.

@winzaa123
Last active February 25, 2019 06:16
Show Gist options
  • Save winzaa123/2b7ce3876807166a4ec9d3381d71c042 to your computer and use it in GitHub Desktop.
Save winzaa123/2b7ce3876807166a4ec9d3381d71c042 to your computer and use it in GitHub Desktop.
modal Promise Vue
<template>
<div class="modal" :class="[{'show fade':dialogConfirm}]" :style="{display: dialogConfirm?'block':'none' }">
<div class="modal-backdrop" :class="[{'show fade':dialogConfirm}]" @click="cancel"></div>
<div class="modal-dialog" @click="cancel">
<div class="modal-content" style="z-index: 1050;">
<header class="modal-header">
<p class="modal-title">{{ title }}</p>
</header>
<section class="modal-body" v-show="!!message">
{{ message }}
<!-- Content ... -->
</section>
<footer class="modal-footer" >
<button class="btn " @click="cancel">Cancel</button>
<button class="btn " :class="options.color" @click="agree">Yes</button>
</footer>
</div>
</div>
</div>
</template>
<script>
export default {
data: () => ({
dialogConfirm: false,
resolve: null,
reject: null,
message: null,
title: '',
options: {
color: 'btn-primary'
}
}),
methods: {
open(title, message, options) {
this.dialogConfirm = true
this.title = title
this.message = message
this.options = Object.assign(this.options, options)
return new Promise((resolve, reject) => {
this.resolve = resolve
this.reject = reject
})
},
agree() {
this.resolve(true)
this.dialogConfirm = false
},
cancel() {
this.resolve(false)
this.dialogConfirm = false
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment