Skip to content

Commit 20981f3

Browse files
docs(vue): streamline usage examples with script setup syntax (#2956)
* chore(docs): streamline demo using script setup syntax Simplifies usage demo using Vue’s script setup syntax. --------- Co-authored-by: Shawn Taylor <[email protected]>
1 parent 8ad4e0a commit 20981f3

File tree

20 files changed

+210
-453
lines changed

20 files changed

+210
-453
lines changed

static/usage/v7/alert/buttons/vue.md

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,32 @@
1111
<p>{{ roleMessage }}</p>
1212
</template>
1313

14-
<script lang="ts">
14+
<script lang="ts" setup>
1515
import { ref } from 'vue';
1616
import { IonAlert, IonButton } from '@ionic/vue';
1717
18-
export default {
19-
components: { IonAlert, IonButton },
20-
setup() {
21-
const handlerMessage = ref('');
22-
const roleMessage = ref('');
18+
const handlerMessage = ref('');
19+
const roleMessage = ref('');
2320
24-
const alertButtons = [
25-
{
26-
text: 'Cancel',
27-
role: 'cancel',
28-
handler: () => {
29-
handlerMessage.value = 'Alert canceled';
30-
},
31-
},
32-
{
33-
text: 'OK',
34-
role: 'confirm',
35-
handler: () => {
36-
handlerMessage.value = 'Alert confirmed';
37-
},
38-
},
39-
];
40-
41-
const setResult = (ev: CustomEvent) => {
42-
roleMessage.value = `Dismissed with role: ${ev.detail.role}`;
43-
};
44-
45-
return {
46-
handlerMessage,
47-
roleMessage,
48-
alertButtons,
49-
setResult,
50-
};
21+
const alertButtons = [
22+
{
23+
text: 'Cancel',
24+
role: 'cancel',
25+
handler: () => {
26+
handlerMessage.value = 'Alert canceled';
27+
},
5128
},
29+
{
30+
text: 'OK',
31+
role: 'confirm',
32+
handler: () => {
33+
handlerMessage.value = 'Alert confirmed';
34+
},
35+
},
36+
];
37+
38+
const setResult = (ev: CustomEvent) => {
39+
roleMessage.value = `Dismissed with role: ${ev.detail.role}`;
5240
};
5341
</script>
5442
```

static/usage/v7/alert/customization/vue.md

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,19 @@
44
<ion-alert trigger="present-alert" class="custom-alert" header="Are you sure?" :buttons="alertButtons"></ion-alert>
55
</template>
66

7-
<script lang="ts">
7+
<script lang="ts" setup>
88
import { IonAlert, IonButton } from '@ionic/vue';
99
10-
export default {
11-
components: { IonAlert, IonButton },
12-
setup() {
13-
const alertButtons = [
14-
{
15-
text: 'No',
16-
cssClass: 'alert-button-cancel',
17-
},
18-
{
19-
text: 'Yes',
20-
cssClass: 'alert-button-confirm',
21-
},
22-
];
23-
24-
return { alertButtons };
10+
const alertButtons = [
11+
{
12+
text: 'No',
13+
cssClass: 'alert-button-cancel',
2514
},
26-
};
15+
{
16+
text: 'Yes',
17+
cssClass: 'alert-button-confirm',
18+
},
19+
];
2720
</script>
2821

2922
<style>

static/usage/v7/alert/inputs/radios/vue.md

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,26 @@
99
></ion-alert>
1010
</template>
1111

12-
<script lang="ts">
12+
<script lang="ts" setup>
1313
import { IonAlert, IonButton } from '@ionic/vue';
1414
15-
export default {
16-
components: { IonAlert, IonButton },
17-
setup() {
18-
const alertButtons = ['OK'];
19-
const alertInputs = [
20-
{
21-
label: 'Red',
22-
type: 'radio',
23-
value: 'red',
24-
},
25-
{
26-
label: 'Blue',
27-
type: 'radio',
28-
value: 'blue',
29-
},
30-
{
31-
label: 'Green',
32-
type: 'radio',
33-
value: 'green',
34-
},
35-
];
36-
37-
return { alertButtons, alertInputs };
15+
const alertButtons = ['OK'];
16+
const alertInputs = [
17+
{
18+
label: 'Red',
19+
type: 'radio',
20+
value: 'red',
21+
},
22+
{
23+
label: 'Blue',
24+
type: 'radio',
25+
value: 'blue',
26+
},
27+
{
28+
label: 'Green',
29+
type: 'radio',
30+
value: 'green',
3831
},
39-
};
32+
];
4033
</script>
4134
```

static/usage/v7/alert/inputs/text-inputs/vue.md

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,30 @@
99
></ion-alert>
1010
</template>
1111

12-
<script lang="ts">
12+
<script lang="ts" setup>
1313
import { IonAlert, IonButton } from '@ionic/vue';
1414
15-
export default {
16-
components: { IonAlert, IonButton },
17-
setup() {
18-
const alertButtons = ['OK'];
19-
const alertInputs = [
20-
{
21-
placeholder: 'Name',
22-
},
23-
{
24-
placeholder: 'Nickname (max 8 characters)',
25-
attributes: {
26-
maxlength: 8,
27-
},
28-
},
29-
{
30-
type: 'number',
31-
placeholder: 'Age',
32-
min: 1,
33-
max: 100,
34-
},
35-
{
36-
type: 'textarea',
37-
placeholder: 'A little about yourself',
38-
},
39-
];
40-
41-
return { alertButtons, alertInputs };
15+
const alertButtons = ['OK'];
16+
const alertInputs = [
17+
{
18+
placeholder: 'Name',
19+
},
20+
{
21+
placeholder: 'Nickname (max 8 characters)',
22+
attributes: {
23+
maxlength: 8,
24+
},
25+
},
26+
{
27+
type: 'number',
28+
placeholder: 'Age',
29+
min: 1,
30+
max: 100,
31+
},
32+
{
33+
type: 'textarea',
34+
placeholder: 'A little about yourself',
4235
},
43-
};
36+
];
4437
</script>
4538
```

static/usage/v7/alert/presenting/controller/vue.md

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,18 @@
33
<ion-button @click="presentAlert">Click Me</ion-button>
44
</template>
55

6-
<script lang="ts">
6+
<script lang="ts" setup>
77
import { IonButton, alertController } from '@ionic/vue';
88
9-
export default {
10-
components: { IonButton },
11-
setup() {
12-
const presentAlert = async () => {
13-
const alert = await alertController.create({
14-
header: 'Alert',
15-
subHeader: 'Important message',
16-
message: 'This is an alert!',
17-
buttons: ['OK'],
18-
});
9+
const presentAlert = async () => {
10+
const alert = await alertController.create({
11+
header: 'Alert',
12+
subHeader: 'Important message',
13+
message: 'This is an alert!',
14+
buttons: ['OK'],
15+
});
1916
20-
await alert.present();
21-
};
22-
23-
return { presentAlert };
24-
},
17+
await alert.present();
2518
};
2619
</script>
2720
```

static/usage/v7/alert/presenting/isOpen/vue.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,15 @@
1111
></ion-alert>
1212
</template>
1313

14-
<script lang="ts">
14+
<script lang="ts" setup>
1515
import { ref } from 'vue';
1616
import { IonAlert, IonButton } from '@ionic/vue';
1717
18-
export default {
19-
components: { IonAlert, IonButton },
20-
setup() {
21-
const isOpen = ref(false);
22-
const alertButtons = ['OK'];
18+
const isOpen = ref(false);
19+
const alertButtons = ['OK'];
2320
24-
const setOpen = (state: boolean) => {
25-
isOpen.value = state;
26-
};
27-
28-
return { isOpen, alertButtons, setOpen };
29-
},
21+
const setOpen = (state: boolean) => {
22+
isOpen.value = state;
3023
};
3124
</script>
3225
```

static/usage/v7/alert/presenting/trigger/vue.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,9 @@
1010
></ion-alert>
1111
</template>
1212

13-
<script lang="ts">
13+
<script lang="ts" setup>
1414
import { IonAlert, IonButton } from '@ionic/vue';
1515
16-
export default {
17-
components: { IonAlert, IonButton },
18-
setup() {
19-
const alertButtons = ['OK'];
20-
21-
return { alertButtons };
22-
},
23-
};
16+
const alertButtons = ['OK'];
2417
</script>
2518
```

static/usage/v7/input/counter/vue.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,11 @@
1212
></ion-input>
1313
</template>
1414

15-
<script lang="ts">
15+
<script lang="ts" setup>
1616
import { IonInput } from '@ionic/vue';
17-
import { defineComponent } from 'vue';
1817
19-
export default defineComponent({
20-
components: { IonInput },
21-
methods: {
22-
customFormatter(inputLength, maxLength) {
23-
return `${maxLength - inputLength} characters remaining`;
24-
},
25-
},
26-
});
18+
const customFormatter = (inputLength, maxLength) => {
19+
return `${maxLength - inputLength} characters remaining`;
20+
};
2721
</script>
2822
```

static/usage/v7/modal/controller/vue/example_vue.md

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,25 @@
1313
</ion-page>
1414
</template>
1515

16-
<script lang="ts">
16+
<script lang="ts" setup>
1717
import { IonButton, IonContent, IonPage, IonHeader, IonToolbar, IonTitle, modalController } from '@ionic/vue';
1818
import Modal from './Modal.vue';
19+
import { ref } from 'vue';
1920
20-
export default {
21-
components: { IonButton, IonContent, IonPage, IonHeader, IonToolbar, IonTitle },
22-
data() {
23-
return {
24-
message: 'This modal example uses the modalController to present and dismiss modals.',
25-
};
26-
},
27-
methods: {
28-
async openModal() {
29-
const modal = await modalController.create({
30-
component: Modal,
31-
});
32-
modal.present();
21+
const message = ref('This modal example uses the modalController to present and dismiss modals.');
3322
34-
const { data, role } = await modal.onWillDismiss();
23+
const openModal = async () => {
24+
const modal = await modalController.create({
25+
component: Modal,
26+
});
3527
36-
if (role === 'confirm') {
37-
this.message = `Hello, ${data}!`;
38-
}
39-
},
40-
},
28+
modal.present();
29+
30+
const { data, role } = await modal.onWillDismiss();
31+
32+
if (role === 'confirm') {
33+
message.value = `Hello, ${data}!`;
34+
}
4135
};
4236
</script>
4337
```

static/usage/v7/modal/controller/vue/modal_vue.md

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</ion-content>
1919
</template>
2020

21-
<script lang="ts">
21+
<script lang="ts" setup>
2222
import {
2323
IonContent,
2424
IonHeader,
@@ -30,19 +30,10 @@
3030
IonInput,
3131
modalController,
3232
} from '@ionic/vue';
33-
import { defineComponent } from 'vue';
33+
import { defineComponent, ref } from 'vue';
34+
const name = ref();
3435
35-
export default defineComponent({
36-
name: 'Modal',
37-
components: { IonContent, IonHeader, IonTitle, IonToolbar, IonButtons, IonButton, IonItem, IonInput },
38-
methods: {
39-
cancel() {
40-
return modalController.dismiss(null, 'cancel');
41-
},
42-
confirm() {
43-
return modalController.dismiss(this.name, 'confirm');
44-
},
45-
},
46-
});
36+
const cancel = () => modalController.dismiss(null, 'cancel');
37+
const confirm = () => modalController.dismiss(name.value, 'confirm');
4738
</script>
4839
```

0 commit comments

Comments
 (0)