Posted inTechnology / Programming / VueJs

Vuejs autocomplete search with typeahead js

Today, We want to share with you Vuejs autocomplete search with typeahead.js.In this post we will show you Vue AutoComplete TextBox Component, hear for Popular Vue autocomplete Component we will give you demo and example for implement.In this post, we will learn about Building an Autocomplete Component with Vue.js with an example.

Vuejs autocomplete search with typeahead.js

There are the Following The simple About Vuejs autocomplete search with typeahead.js Full Information With Example and source code.

As I will cover this Post with live Working example to develop Autocomplete Field using Vue.js, so the bootstrap-vue autocomplete for this example is following below.

HTML Part

form auto complete

Single Select

Selected programmingLang :
lid: {{programmingLangA.lid}}
title: {{programmingLangA.title}}

Multi Select

Selected programmingLang :

lid: {{v.lid}} - title: {{v.title}}

Single Select - with Scope Slot

Selected programmingLang :
lid: {{programmingLangB.lid}}
title: {{programmingLangB.title}}

Multi Select - with Scope Slot

Selected programmingLang :

lid: {{v.lid}} - title: {{v.title}}

Single Select - Default value

Selected programmingLang :
lid: {{programmingLangC.lid}}
title: {{programmingLangC.title}}

Multi Select - Default Value

Selected programmingLang :

lid: {{v.lid}} - title: {{v.title}}

CSS Part

.d-flex {
  display: flex;
  flex-wrap: wrap;
}
.d-flex-lang {
  width: 300px;
  padding: 10px;
  border: 1px solid #eaeaea;
  margin: 0 20px 20px 0;
}
.form-autocomplete {
  padding: 10px;
  background: #eaeaea;
}

ul {
  width: 200px;
  padding-left: 0;
}
ul > li {
  cursor: pointer;
  list-style: none;
  padding: 5px;
  margin-bottom: 5px;
  border: 1px solid white;
  background: #dedede;
}
ul > li:hover {
  background: #313131;
  color: white;
}
ul > li.disabled,
ul > li.disabled:hover {
  background: #eaeaea;
  color: #a7a7a7;
  cursor: inherit;
}
ul > li.disabled .flag-icon {
  opacity: 0.5;
}

.langs-selected {
  margin-top: 20px;
}
.lang-selected {
  border-radius: 5px;
  display: inline-block;
  padding: 5px;
  background: #7b8fdc;
  color: white;
  margin: 0 5px 10px 0;
}

Js Part

const countries = [
  { lid: 'AU', title: 'Laravel' },
  { lid: 'ID', title: 'Angularjs' },
  { lid: 'KR', title: 'PHP' },
  { lid: 'NZ', title: 'Magento' },
];

Vue.component('form-autocomplete', {
  template: 
    `
{{value.lid}} - {{value.title}}
  • {{lang.title}}
  • Item not found
{{v.lid}} - {{v.title}}
  • {{lang.title}}
  • Item not found
` , props: { isMultiple: { type: Boolean, default: false, }, placeholder: { type: String, default: '', }, options: { type: Array, default() { return []; }, }, value: { type: [Object, Array], default() { return { lid: undefined, title: undefined, }; }, }, }, data() { return { textSearch: '', isShow: false, }; }, computed: { filteredOptions() { return this.options.filter(val => val.title.toLowerCase().includes(this.textSearch.toLowerCase())); }, selectedItems() { if (this.isMultiple) { return this.value.map(v => v.lid); } return []; }, }, methods: { inSelectedItems(lid) { return this.selectedItems.includes(lid); }, showOptions() { this.isShow = true; }, selectItem(lang) { this.textSearch = ''; this.isShow = false; // this.$emit('update:lang', lang); this.$emit('input', lang); this.$emit('onSelectItem', lang); }, clearItem() { this.textSearch = ''; // this.$emit('update:lang', { // id: undefined, // title: undefined, // }); this.$emit('input', { id: undefined, title: undefined, }); this.$emit('onClearItem'); }, addItem(lang) { if (!this.inSelectedItems(lang.lid)) { this.textSearch = ''; this.isShow = false; const langs = JSON.parse(JSON.stringify(this.value)); langs.push(lang); // this.$emit('update:lang', langs); this.$emit('input', langs); this.$emit('onAddItem', langs); } }, removeItem(index) { this.textSearch = ''; const langs = JSON.parse(JSON.stringify(this.value)); langs.splice(index, 1); // this.$emit('update:lang', langs); this.$emit('input', langs); this.$emit('onRemoveItem', langs); }, }, }); new Vue({ el: '#app', data() { return { programmingLangA: { lid: undefined, title: undefined, }, programmingLangB: { lid: undefined, title: undefined, }, programmingLangC: { lid: 'ID', title: 'Angularjs', }, multiLanguageA: [], multiLanguageB: [], multiLanguageC: [ { lid: 'ID', title: 'Angularjs' }, { lid: 'AU', title: 'Laravel' }, ], }; }, methods: { toLowerCase(text) { return text.toLowerCase(); }, }, });
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Vuejs autocomplete search with typeahead.js.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype