uiv: Bootstrap 3 Components for Vue 3
uiv is a lightweight collection of Bootstrap 3 components meticulously re-implemented for Vue.js. The current stable version, 2.0.6, targets Vue 3, while previous 1.x versions supported Vue 2. The library is actively maintained with frequent bug fix releases, as seen in the recent 2.0.x updates. Key differentiators include its small bundle size (approximately 20KB gzipped for all components), absence of an additional CSS file (relying on Bootstrap's own styles), support for individual component imports to minimize payload, and compatibility with Server-Side Rendering (SSR). It provides a comprehensive set of common UI elements like Modals, Tabs, Dropdowns, and more, enabling developers to build Bootstrap-styled interfaces using Vue's reactivity system. This library aims to provide a native Vue experience for Bootstrap 3, distinguishing itself from wrappers that might rely on jQuery or other external dependencies for component logic.
Common errors
-
Failed to resolve component: uiv-modal
cause The uiv library or a specific component was not correctly registered with the Vue application.fixEnsure you have `app.use(uiv)` in your main application entry point (e.g., `main.js`) if you are using global registration. Alternatively, if importing individual components, make sure they are properly imported and registered locally or globally. -
TypeError: Cannot read properties of undefined (reading 'use')
cause `app` is not a valid Vue 3 application instance, or you are trying to use `app.use()` on a Vue 2 instance or a non-Vue object.fixConfirm you are creating your Vue application with `createApp()` (Vue 3) and that `app` refers to the return value of this function, e.g., `const app = createApp(App)`. -
Uncaught TypeError: $(...).tooltip is not a function
cause This error typically indicates that jQuery and Bootstrap's JavaScript (which depends on jQuery for its components like tooltips) are not loaded or initialized, but uiv does not depend on them. If you see this error, it's likely from *another* Bootstrap-related library or custom script, not uiv itself. uiv is jQuery-free.fixThis error is generally NOT related to `uiv`. If you encounter it, check if you have other Bootstrap-related JavaScript libraries or custom scripts that mistakenly expect jQuery and Bootstrap's JS. uiv components are implemented natively in Vue.
Warnings
- breaking uiv v2.0.0 and above are exclusively for Vue 3. Projects using Vue 2 must remain on uiv v1.x (or v0.x). The API might have minor changes due to Vue 3's composition API and other breaking changes.
- gotcha uiv components require Bootstrap 3's CSS for proper styling. The library does not bundle this CSS. Failing to import `bootstrap/dist/css/bootstrap.min.css` (or a custom Bootstrap build) will result in unstyled components.
- gotcha The `Btn` component in uiv v2.0.6 (and potentially earlier v2 versions) internally uses `RouterLink` from `vue-router`. If `vue-router` is not installed and configured in your Vue 3 application, using the `Btn` component may lead to errors or unexpected behavior, especially when attempting to use its routing capabilities.
- gotcha Directives like `v-uiv-tooltip` or `v-uiv-popover` are provided. Remember to register uiv as a plugin (`app.use(uiv)`) for these directives to be globally available. If only specific components are imported, directives will not be automatically registered.
Install
-
npm install uiv -
yarn add uiv -
pnpm add uiv
Imports
- * as uiv
const uiv = require('uiv')import * as uiv from 'uiv'
- Specific Component (e.g., Modal)
import Modal from 'uiv/components/modal'
import { Modal } from 'uiv' - Bootstrap CSS
import 'uiv/dist/uiv.min.css'
import 'bootstrap/dist/css/bootstrap.min.css'
- Types (for TypeScript)
import type { DropdownOption } from 'uiv'
Quickstart
import 'bootstrap/dist/css/bootstrap.min.css'
import { createApp, h } from 'vue'
import * as uiv from 'uiv'
const App = {
template: `
<div class="container">
<h1>uiv Example</h1>
<button type="button" class="btn btn-primary" @click="showModal = true">
Open Modal
</button>
<uiv-modal v-model="showModal" title="Hello uiv!" @hide="onModalHide">
This is a simple modal dialog using uiv components. Ensure Bootstrap CSS is imported!
<template #footer>
<button type="button" class="btn btn-default" @click="showModal = false">Close</button>
<button type="button" class="btn btn-primary" @click="showAlert">Do Something</button>
</template>
</uiv-modal>
</div>
`,
data() {
return {
showModal: false
}
},
methods: {
onModalHide() {
console.log('Modal was hidden')
},
showAlert() {
alert('Action taken!')
this.showModal = false
}
}
}
const app = createApp(App)
app.use(uiv)
app.mount('#app')