Vue.js Typeahead/Autocomplete for Bootstrap 4

2.12.0 · active · verified Sun Apr 19

Vue Typeahead Bootstrap is an autocomplete component for Vue 2 applications, specifically designed to integrate with Bootstrap 4's styling and utility classes. It provides a `list-group` based interface for suggestions, supporting features like custom suggestion slots and event emission for focus/blur. The project is currently at version 2.12.0, with recent releases indicating ongoing maintenance and minor feature enhancements (e.g., v2.13.0 recently). It serves as a spiritual successor to the `vue-bootstrap-typeahead` project, which lost its maintainer, ensuring continued support for users requiring a Bootstrap 4 compatible typeahead in their Vue 2 applications. Its primary differentiators are its strong coupling with Bootstrap 4 and its dedicated support for Vue 2, making it a suitable choice for legacy projects or those specifically constrained to these versions.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates global registration of the VueTypeaheadBootstrap component, rendering it in a basic Vue application, and binding data.

import Vue from 'vue';
import App from './App.vue';
import 'bootstrap/dist/css/bootstrap.min.css'; // Ensure Bootstrap CSS is loaded
import VueTypeaheadBootstrap from 'vue-typeahead-bootstrap';

Vue.component('vue-typeahead-bootstrap', VueTypeaheadBootstrap);

new Vue({
  el: '#app',
  template: `
    <div id="app" class="container mt-5">
      <h1>Search Countries</h1>
      <vue-typeahead-bootstrap
        v-model="selectedCountry"
        :data="countries"
        placeholder="Type a country..."
        @hit="countrySelected"
        size="lg"
      ></vue-typeahead-bootstrap>
      <p v-if="selectedCountry" class="mt-3">Selected: {{ selectedCountry }}</p>
    </div>
  `,
  data() {
    return {
      selectedCountry: null,
      countries: [
        'United States', 'Canada', 'Mexico', 'Brazil', 'Argentina',
        'United Kingdom', 'France', 'Germany', 'Italy', 'Spain',
        'China', 'India', 'Japan', 'Australia', 'South Africa'
      ]
    };
  },
  methods: {
    countrySelected(item) {
      console.log('Selected item:', item);
    }
  }
});

view raw JSON →