|
4 | 4 | <q-dialog |
5 | 5 | v-model="showDialog" |
6 | 6 | ref="dialog" |
7 | | - title="The title" |
8 | | - message="The message" |
9 | | - @show="onShow" |
10 | | - @hide="onHide" |
| 7 | + stack-buttons |
11 | 8 | @cancel="onCancel" |
12 | 9 | @ok="onOk" |
| 10 | + @show="onShow" |
| 11 | + @hide="onHide" |
13 | 12 | > |
14 | | - <!-- <template slot="buttons" slot-scope="props"> |
15 | | - <q-btn flat label="Cancel" @click="props.cancel(onCancel)" /> |
16 | | - <q-btn flat label="OK" @click="props.ok(onOK)" /> |
17 | | - </template> --> |
| 13 | + <!-- This or use "title" prop on <q-dialog> --> |
| 14 | + <span slot="title">Favorite Superhero</span> |
| 15 | + |
| 16 | + <!-- This or use "message" prop on <q-dialog> --> |
| 17 | + <span slot="message">What is your superhero of choice?</span> |
| 18 | + |
| 19 | + <div slot="body"> |
| 20 | + <q-field |
| 21 | + icon="account_circle" |
| 22 | + helper="We need your name so we can send you to the movies." |
| 23 | + label="Your name" |
| 24 | + :label-width="3" |
| 25 | + :error="nameError" |
| 26 | + > |
| 27 | + <q-input v-model="name" /> |
| 28 | + </q-field> |
| 29 | + </div> |
| 30 | + |
| 31 | + <template slot="buttons" slot-scope="props"> |
| 32 | + <q-btn color="primary" label="Choose Superman" @click="choose(props.ok, 'Superman')" /> |
| 33 | + <q-btn color="black" label="Choose Batman" @click="choose(props.ok, 'Batman')" /> |
| 34 | + <q-btn color="negative" label="Choose Spiderman" @click="choose(props.ok, 'Spiderman')" /> |
| 35 | + <q-btn flat label="No thanks" @click="props.cancel()" /> |
| 36 | + </template> |
18 | 37 | </q-dialog> |
19 | 38 |
|
20 | 39 | {{ showDialog }} |
|
30 | 49 |
|
31 | 50 | <script> |
32 | 51 | export default { |
33 | | - data () { |
34 | | - return { |
35 | | - showDialog: false |
36 | | - } |
37 | | - }, |
38 | 52 | methods: { |
| 53 | + openSpecialPosition (position) { |
| 54 | + this.$q.dialog({ |
| 55 | + title: 'Positioned', |
| 56 | + message: `This dialog appears from ${position}.`, |
| 57 | + position |
| 58 | + }) |
| 59 | + }, |
39 | 60 | toggle () { |
40 | 61 | this.$refs.dialog.show() |
41 | 62 | }, |
42 | 63 | toggle2 () { |
43 | 64 | this.showDialog = !this.showDialog |
44 | 65 | }, |
45 | | - onOk (data) { |
46 | | - console.log('>>> onOK', data) |
| 66 | + onOk () { |
| 67 | + console.log('ok') |
47 | 68 | }, |
48 | | - onCancel (data) { |
49 | | - console.log('>>> onCancel', data) |
| 69 | + onCancel () { |
| 70 | + console.log('cancel') |
50 | 71 | }, |
51 | | - onHide (data) { |
52 | | - console.log('>>> onHide', data) |
| 72 | + onShow () { |
| 73 | + console.log('show') |
53 | 74 | }, |
54 | | - onShow (data) { |
55 | | - console.log('>>> onShow', data) |
| 75 | + onHide () { |
| 76 | + console.log('hide') |
| 77 | + }, |
| 78 | + async choose (okFn, hero) { |
| 79 | + if (this.name.length === 0) { |
| 80 | + this.error = true |
| 81 | + this.$q.dialog({ |
| 82 | + title: 'Please specify your name!', |
| 83 | + message: `Can't buy tickets without knowing your name.` |
| 84 | + }) |
| 85 | + } |
| 86 | + else { |
| 87 | + await okFn() |
| 88 | + this.$q.notify(`Ok ${this.name}, going with ${hero}`) |
| 89 | + } |
56 | 90 | }, |
57 | 91 | adHoc () { |
58 | 92 | this.$q.dialog({ |
@@ -106,6 +140,21 @@ export default { |
106 | 140 | console.log('>>> Cancel') |
107 | 141 | }) |
108 | 142 | } |
| 143 | + }, |
| 144 | + watch: { |
| 145 | + name (val) { |
| 146 | + const err = val.length === 0 |
| 147 | + if (this.nameError !== err) { |
| 148 | + this.nameError = err |
| 149 | + } |
| 150 | + } |
| 151 | + }, |
| 152 | + data () { |
| 153 | + return { |
| 154 | + showDialog: false, |
| 155 | + name: '', |
| 156 | + nameError: false |
| 157 | + } |
109 | 158 | } |
110 | 159 | } |
111 | 160 | </script> |
0 commit comments