Global API
Functional API provided by Vue MDBootstrap.
createVueMdb
Creates an application instance and register all components, plugins and directives.
function createVueMdb(rootComponent: Component): AppExample
With inline root component:
import { createVueMdb } from 'vue-mdbootstrap';
const app = createVueMdb({
/* root component options */
});
app.mount('#app');With imported component:
import { createVueMdb } from 'vue-mdbootstrap';
import App from './App.vue';
const app = createVueMdb(App);
app.mount('#app');Standalone web page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous"/>
<link href="https://cdn.jsdelivr.net/npm/vue-mdbootstrap@2/dist/bundle-core.min.css" rel="stylesheet" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/vue-mdbootstrap@2/dist/theme-light.min.css" rel="stylesheet" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-mdbootstrap@2/dist/vue-mdb.umd.min.js" crossorigin="anonymous"></script>
</head>
<body>
<div id="app" class="container">
<h3 class="mt-4">Contextual Buttons</h3>
<bs-card class="mt-4">
<bs-card-body>
<div class="flex flex-wrap md-gap-3">
<bs-button @click="count++">Click me</bs-button>
<bs-button color="primary" @click="count++">Click me</bs-button>
<bs-button color="secondary" @click="count++">Click me</bs-button>
<bs-button color="success" @click="count++">Click me</bs-button>
<bs-button color="danger" @click="count++">Click me</bs-button>
<bs-button color="warning" @click="count++">Click me</bs-button>
<bs-button color="info" @click="count++">Click me</bs-button>
</div>
</bs-card-body>
<bs-card-footer class="font-weight-semibold">Count: {{ count }}</bs-card-footer>
</bs-card>
</div>
<script>
const { ref } = Vue;
const { createVueMdb } = VueMdb;
const app = createVueMdb({
setup() {
const count = ref(0);
return {count};
}
});
app.mount('#app');
</script>
</body>
</html>useAxiosPlugin
Vue MDBootstrap provides built-in axios plugin to perform HTTP request. This function retrieve axios plugin instance. Must be called within component or within <script setup>.
function useAxiosPlugin(): AxiosInstance | undefinedSee axios library for the instance method details.
Example
import { useAxiosPlugin } from 'vue-mdbootstrap';
const axios = useAxiosPlugin();
const response = await axios?.get("<api-url>");useHttpService
Retrieve HTTP service plugin instance. This instance will forward all the HTTP request task to the axios plugin. Must be called within component or within <script setup>.
function useHttpService(): IHttpService | undefinedExample
import { useHttpService } from 'vue-mdbootstrap';
const http = useHttpService();
const response = await http?.get("<api-url>");Instance Method
- getts
interface IHttpService { get(url: string, data?: TRecord, options?: RawAxiosRequestConfig): AxiosPromise; }Send HTTP GET to the remote service.
Details:
url: the API urldata: the data to be sent (optional)options: Additional options (optional)
- patchts
interface IHttpService { patch(url: string, data: TRecord | FormData, options?: RawAxiosRequestConfig): AxiosPromise; }Send HTTP PATCH to the remote service.
Details:
url: the API urldata: the data to be sentoptions: Additional options (optional)
- postts
interface IHttpService { post(url: string, data: TRecord | FormData, options?: RawAxiosRequestConfig): AxiosPromise; }Send HTTP POST to the remote service.
Details:
url: the API urldata: the data to be sentoptions: Additional options (optional)
- putts
interface IHttpService { put(url: string, data: TRecord | FormData, options?: RawAxiosRequestConfig): AxiosPromise; }Send HTTP PUT to the remote service.
Details:
url: the API urldata: the data to be sentoptions: Additional options (optional)
- deletets
interface IHttpService { delete(url: string, data?: TRecord, options?: RawAxiosRequestConfig): AxiosPromise; }Send HTTP DELETE to the remote service.
Details:
url: the API urldata: the data to be sent (optional)options: Additional options (optional)
useVueMdbService
Shortcut to retrieve the VueMdb plugin instance.
function useVueMdbService(): TVueMdb | undefineduseVueMdbNotification
Shortcut to retrieve the INotificationProvider instance. See Notification component for more details.
function useVueMdbNotification(): INotificationProvider | undefinedExample
import { useVueMdbNotification } from 'vue-mdbootstrap';
const notification = useVueMdbNotification();
notification?.success("Your message");
notification?.warning("Your message", "Message Title");useBreakpointMax
Simple function to detect whether a device's screen is within allowable maximum screen resolution. Returns true when the screen resolution is within allowable resolution otherwise false. Available breakpoints are: xs, sm, md, lg, and xl.
function useBreakpointMax(breakpoint: TBreakpoint | number): booleanSee Bootstrap Breakpoints for more details.
Example
import { ref } from 'vue';
import { useBreakpointMax } from 'vue-mdbootstrap';
const appCpanel = ref({
isMobile: false,
isTablet: false,
isDesktop: true,
sideDrawerOpen: !useBreakpointMax('lg'),
});
if (useBreakpointMax('lg')) {
appCpanel.value.sideDrawerOpen = false;
appCpanel.value.isTablet = true;
appCpanel.value.isMobile = false;
appCpanel.value.isDesktop = false;
}useBreakpointMin
Simple function to detect whether a device's screen is within allowable minimum screen resolution. Returns true when the screen resolution is within allowable resolution otherwise false. Available breakpoints are: xs, sm, md, lg, and xl.
function useBreakpointMin(breakpoint: TBreakpoint | number): booleanSee Bootstrap Breakpoints for more details.
Example
import { ref } from 'vue';
import { useBreakpointMin } from 'vue-mdbootstrap';
const appCpanel = ref({
isMobile: false,
isTablet: false,
isDesktop: true,
});
if (useBreakpointMin('xl')) {
appCpanel.value.isMobile = false;
appCpanel.value.isTablet = false;
appCpanel.value.isDesktop = true;
}useMobileDevice
Check whether it is using a mobile browser or not. Returns true if mobile browser is used otherwise false.
function useMobileDevice(): booleanuseAddResizeListener
Simple function that use ResizeObserver Web API to detect if an Element's dimension was changed or not. Must be called within component or within <script setup>.
function useAddResizeListener(el: IBindingElement, fn: CallableFunction): voidExample
import { useAddResizeListener } from 'vue-mdbootstrap';
const divElem = document.querySelector("body > div");
function onResize(): void {
// Do some task here
}
onMounted(() => {
useAddResizeListener(divElem as IBindingElement, onResize);
});useRemoveResizeListener
Remove observer from an element and disconnect ResizeObserver instance if no more element to observe. Must be called within component or within <script setup>.
function useRemoveResizeListener(el: IBindingElement, fn?: CallableFunction): voidExample
import { useAddResizeListener, useRemoveResizeListener } from 'vue-mdbootstrap';
const divElem = document.querySelector("body > div");
function onResize(): void {
// Do some task here
}
onMounted(() => {
useAddResizeListener(divElem as IBindingElement, onResize);
});
onBeforeUnmount(() => {
useRemoveResizeListener(divElem as IBindingElement, onResize);
});useCurrentRoute
Get current active route if exists. Returns current route location if Vue Router instance already loaded.
function useCurrentRoute(): Ref<RouteLocationNormalizedLoaded> | undefineduseGenerateId
Generate component's ID.
function useGenerateId(): stringuseMergeClass
Added in v2.1.0Merge one or more CSS classes.
function useMergeClass(...args: (string | string[])[]): string[]Details:
args: The CSS classes to be merged.
useRenderSlot
Added in v2.1.0Simple function to render a VNode with custom slot. If the custom slot doesn't exist or undefined then the default children will be rendered.
function useRenderSlot(
slots: Slots,
name: string,
props: Readonly<TRecord>,
children?: VNodeArrayChildren | VNode,
slotArgs?: TRecord
): VNodeDetails:
slots: The slot instancename: The slot nameprops: VNode property, include slot identifierchildren: The default VNode children to replace the slot (optional)slotArgs: The argument for the given slot (optional)
useRenderSVG
Added in v2.1.0Function to draw inline SVG xml directly.
function useRenderSVG(
data: string,
width: number,
height: number,
clazz: string | string[]
): VNodeDetails:
useRenderTransition
Added in v2.1.0Simple function to render a Transition component.
function useRenderTransition(
props: Readonly<TransitionProps>,
children: VNodeArrayChildren | VNode,
asBlock?: boolean
): VNodeDetails:
props: The transition propertieschildren: The child nodesasBlock: Render the Transition as block VNode (optional)
useWrapSlot
Added in v2.2.0Simple function to render a VNode with custom slot and wrap it with the given wrapperTag and properties. If the custom slot doesn't exist or undefined then the default children will be rendered inside the wrapperTag.
function useWrapSlot(
slots: Slots,
name: string,
key: string,
wrapperProps: Readonly<TRecord>,
children?: VNodeArrayChildren | VNode,
wrapperTag?: string,
slotArgs?: TRecord
): VNodeDetails:
slots: The slot instancename: The slot namekey: Fragment key identifierwrapperProps: The VNode wrapper propertieschildren: The default VNode children to replace the slot (optional)wrapperTag: Valid html tag name, default isdiv(optional)slotArgs: The argument for the given slot (optional)
useWrapSlotDefault
Added in v2.2.0Simple function to render an HTML tag as VNode or render default slot and wrap an HTML tag around it.
function useWrapSlotDefault(
tag: string,
slots?: Slots,
classes?: string | string[],
styles?: TRecord
): VNodeDetails:
tag: Valid HTML tag nameslots: The slot instance (optional)classes: Custom CSS classes to apply (optional)styles: Custom inline stylesheet to apply (optional)
useWrapSlotWithCondition
Added in v2.2.0Simple function to render a VNode with custom slot and wrap it with the given wrapTag and properties. The VNode will be rendered if the given condition is matched.
function useWrapSlotWithCondition(
slots: Slots,
name: string,
condition: boolean,
wrapProps?: Readonly<TRecord>,
wrapTag?: string,
slotArgs?: TRecord
): VNode | undefinedDetails:
slots: The slot instancename: The slot namecondition: The given conditionwrapProps: The VNode wrapper properties (optional)wrapTag: Valid html tag name, default isdiv(optional)slotArgs: The argument for the given slot (optional)
