Method call
From internal components
To call a method of a component from a button or other object placed inside the component to be controlled, specify method name=component
to be controlled.
Hello, world! This is a toast message.
vue
<template>
<Toast show>
<ToastHeader>
<b-img
src="https://dummyimage.com/20x20/007aff/007aff"
rounded
margin="e-2"
alt="Card image cap"
/>
<strong class="me-auto">Bootstrap</strong>
<small>11 mins ago</small>
<CloseButton dismiss="toast" />
</ToastHeader>
<ToastBody>Hello, world! This is a toast message.</ToastBody>
</Toast>
</template>
From external components
To call a method of a controlled component from a button or other object placed outside of the controlled component
Set the ID to the component to be controlled, and specify target=#{id} and method name=target
component for buttons, etc.
vue
<template>
<!-- Button trigger modal -->
<b-button
color="primary"
toggle="modal"
target="#exampleModal"
>
Launch demo modal
</b-button>
<!-- Modal -->
<Modal id="exampleModal">
<ModalDialog>
<ModalContent>
<ModalHeader>
<ModalTitle>Modal title</ModalTitle>
<CloseButton dismiss="modal" />
</ModalHeader>
<ModalBody>...</ModalBody>
<ModalFooter>
<b-button
color="secondary"
dismiss="modal"
>
Close
</b-button>
<b-button color="primary">
Save changes
</b-button>
</ModalFooter>
</ModalContent>
</ModalDialog>
</Modal>
</template>
Scripts
To make method calls on the controlled component by Sciript, use theref.
: :
vue
<template>
<!-- Button trigger modal -->
<b-button
color="primary"
@click="clicked"
>
Launch demo modal
</b-button>
<EventViewer :raised="raised" />
<!-- Modal -->
<Modal
ref="demoModal"
@hide="onHide"
@hidden="onHidden"
@show="onShow"
@shown="onShown"
>
<ModalDialog>
<ModalContent>
<ModalHeader>
<ModalTitle>Modal title</ModalTitle>
<CloseButton dismiss="modal" />
</ModalHeader>
<ModalBody>...</ModalBody>
<ModalFooter>
<b-button
color="secondary"
dismiss="modal"
>
Close
</b-button>
<b-button color="primary">
Save changes
</b-button>
</ModalFooter>
</ModalContent>
</ModalDialog>
</Modal>
</template>
<script setup lang="ts">
import { delay } from 'es-toolkit/compat';
const demoModal = ref(null);
const raised = ref({ name: '', event: '' });
const clicked = () => {
delay(() => {
if (demoModal.value) {
demoModal.value.show();
}
}, 1000);
};
const onHide = () => {
raised.value = { name: 'Modal', event: 'Hide' };
};
const onHidden = () => {
raised.value = { name: 'Modal', event: 'Hidden' };
};
const onShow = () => {
raised.value = { name: 'Modal', event: 'Show' };
};
const onShown = () => {
raised.value = { name: 'Modal', event: 'Shown' };
};
</script>
Components
Accordion Item
Method | Description |
---|---|
toggle | Switch manually |
show | Open manually |
hide | Manually hide |
Alert
Method | Description |
---|---|
toggle | Manual switching |
show | Manually show |
hide | Manually hide |
Carousel
Method | Description |
---|---|
cycle | Circulate items from left to right |
pause | Stop circulating items |
prev | Circulate to previous item |
next | Circulate to next item |
to | Circulate to specific items |
Collapse
Method | Description |
---|---|
toggle | Toggles a collapsible element to shown or hidden. Returns to the caller before the collapsible element has actually been shown or hidden |
show | Shows a collapsible element. Returns to the caller before the collapsible element has actually been shown |
hide | Hides a collapsible element. Returns to the caller before the collapsible element has actually been hidden |
Dropdowns
Method | Description |
---|---|
toggle | Toggles a collapsible element to shown or hidden. Returns to the caller before the collapsible element has actually been shown or hidden |
show | Shows a collapsible element. Returns to the caller before the collapsible element has actually been shown |
hide | Hides a collapsible element. Returns to the caller before the collapsible element has actually been hidden |
Modal
Method | Description |
---|---|
toggle | Manually switch the modal |
show | Manually open the modal |
hide | Manually hide the modal |
Offcanvas
Method | Description |
---|---|
toggle | Toggles a collapsible element to shown or hidden. Returns to the caller before the collapsible element has actually been shown or hidden |
show | Shows a collapsible element. Returns to the caller before the collapsible element has actually been shown |
hide | Hides a collapsible element. Returns to the caller before the collapsible element has actually been hidden |