Created
October 3, 2022 08:54
-
-
Save tno2007/b7d28e226b73a9503918f0db8abe0893 to your computer and use it in GitHub Desktop.
BootstrapVue Toast in composition API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script setup lang="ts"> | |
import { reactive } from "vue"; | |
const toast = reactive({ | |
message: "", | |
options: { | |
title: "", | |
}, | |
visible: false, | |
}); | |
const showToast = ( | |
message: string = "", | |
options: any = { title: "BootstrapVue Toast" } | |
) => { | |
// set message text | |
toast.message = message; | |
// set options if any | |
if (options) { | |
toast.options = options; | |
} | |
// show toast | |
toast.visible = true; | |
}; | |
</script> | |
<template> | |
<div> | |
<button @click="showToast('A toast in vue composition API!')"> | |
Click me | |
</button> | |
<b-toast :title="toast.options.title" :visible="toast.visible"> | |
{{ toast.message }} | |
</b-toast> | |
</div> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment