q-dialog in async-await way?
-
How to use q-dialog as mixin function using async await?
confirmation(title, msg) { this.$q.dialog({ title: title, message: msg, ok: { push: true }, cancel: { color: 'negative' }, persistent: true }).onOk(() => { return true }).onOk(() => { return true }).onCancel(() => { return false }) }
-
Qdialog does not return a promise it did before in old version but for perf reason it’s dropped. What you could do is wrap it in a promise, then async await the returned promise accordingly.
-
How I usually structure my code is
if(await new Promise(resolve=>this.$q.dialog({ ... cancel:true }).onOk(()=>resolve(true)).onCancel(()=>resolve(false)))){ //ok code }else{ //cancel code }
In that sense the callbacks are more flexible than returning a Promise which calls catch() on cancel, as I would have to wrap my await call in a try block to handle the cancel button if such a Promise were returned (which to me looks more unwieldy than a simple if-else, I prefer using catch to handle real errors).