8000 How to wrap useToast in a seperate class (not inside setup) · bootstrap-vue-next bootstrap-vue-next · Discussion #1829 · GitHub
[go: up one dir, main page]

Skip to content

How to wrap useToast in a seperate class (not inside setup) #1829

Closed Answered by sceee
boindil asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @boindil ,

As useToast is a composable, it "should only be called in <script setup> or the setup() hook."

But you can nest composables to probably achieve what you want (reuse the same configuration across multiple components).

Say you create a ToastHelper.ts with the following content:

import { useToast } from 'bootstrap-vue-next';

export function useSuccessToast() {
  const toast = useToast();

  const showSuccessToast = () =>
    toast.show?.({ props: { title: 'Hello', body: 'World' } });

  return { show: showSuccessToast };
}

And use your own useSuccessToast composable in your components:

<template>
  <BButton @click="onClickDiv">
    {{ msg }}
  </BButton>
</template>
<script se…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by boindil
Comment options

You must be logged in to vote
1 reply
@VividLemon
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
3 participants
@boindil @sceee 8000 @VividLemon
Converted from issue

This discussion was converted from issue #1827 on March 26, 2024 17:52.

0