Skip to content

Instantly share code, notes, and snippets.

@antirek
Forked from skushnerchuk/Dialog.vue
Created March 19, 2021 18:10
Show Gist options
  • Select an option

  • Save antirek/eff9287faa581998af830b3a87131e2e to your computer and use it in GitHub Desktop.

Select an option

Save antirek/eff9287faa581998af830b3a87131e2e to your computer and use it in GitHub Desktop.
Quasar dialog
<template>
<q-dialog ref="dialog" @hide="onDialogHide">
<q-card style="min-width: 450px">
<q-card-section>
<span v-if="title">
{{ title }}
<q-space style="height: 10px"/>
</span>
<q-input
dense
v-model="data"
autofocus
outlined
/>
</q-card-section>
<q-card-actions align="right" class="text-primary">
<q-btn flat label="OK" v-close-popup @click="onOKClick"/>
<q-btn flat label="Cancel" v-close-popup @click="onCancelClick"/>
</q-card-actions>
</q-card>
</q-dialog>
</template>
<script>
export default {
name: 'InputDialog',
data: function () {
return {
data: ''
}
},
props: ['title'],
methods: {
show () {
this.$refs.dialog.show()
},
hide () {
this.$refs.dialog.hide()
},
onDialogHide () {
this.$emit('hide')
},
onOKClick () {
this.$emit('ok', this.data)
this.hide()
},
onCancelClick () {
this.hide()
}
}
}
</script>
export default async ({ Vue }) => {
Vue.mixin({
methods: {
showDialog (options) {
return new Promise((resolve, reject) => {
this.$q.dialog(options).onOk((data) => {
resolve({ ok: true, data: data })
}).onCancel(() => {
resolve({ ok: false })
}).onDismiss(() => {
resolve({ ok: false })
})
})
}
}
})
}
methods: {
...
async callDialog () {
const response = await this.showDialog({
component: InputDialog,
parent: this,
persistent: true,
title: 'Dialog title'
})
if (response.ok) {
console.log(response.data)
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment