<template>
<ion-page>
<ion-content class="ion-padding">
<ion-button @click="openToast">Open Toast</ion-button>
<ion-button @click="openToastOptions">Open Toast: Options</ion-button>
</ion-content>
</ion-page>
</template>
<script>
import { IonButton, IonContent, IonPage, toastController } from '@ionic/vue';
export default {
components: { IonButton, IonContent, IonPage },
methods: {
async openToast() {
const toast = await toastController.create({
message: 'Your settings have been saved.',
duration: 2000,
});
return toast.present();
},
async openToastOptions() {
const toast = await toastController.create({
header: 'Toast header',
message: 'Click to Close',
position: 'top',
buttons: [
{
side: 'start',
icon: 'star',
text: 'Favorite',
handler: () => {
console.log('Favorite clicked');
},
},
{
text: 'Done',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
},
},
],
});
await toast.present();
const { role } = await toast.onDidDismiss();
console.log('onDidDismiss resolved with role', role);
},
},
};
</script>