Giter Club home page Giter Club logo

vue-typeahead's Introduction

VueTypeahead

See a live demo here.

Install

NPM

Available through npm as vue-typeahead.

npm install --save vue-typeahead

Also, you need to install the vue-resource plugin.

Configuration

import VueTypeaheadMixin from 'vue-typeahead'
import VueTypeaheadTemplate from '...'

Vue.component('typeahead', {
  template: VueTypeaheadTemplate,     // optional if you use inline-template
  mixins: [VueTypeaheadMixin],
  data () {
    return {
      src: '...',                     // required
      data: {},                       // optional
      limit: 5,                       // optional
      onHit (item) {                  // required
        // ...
      },
      prepareResponseData (data) {    // optional
        // data = ...
        return data;
      }
    }
  }
});

Use in templates

Import template

You could import the template by set the template key like above.

Inline template

<typeahead inline-template>
    <div class="typeahead">
        <!-- optional indicators -->
        <i class="fa fa-spinner fa-spin" v-if="loading"></i>
        <template v-else>
            <i class="fa fa-search" v-show="isEmpty"></i>
            <i class="fa fa-times" v-show="isDirty" @click="reset"></i>
        </template>

        <!-- the input field -->
        <input type="text"
               placeholder="..."
               autocomplete="off"
               v-model="query"
               @keydown.down="down"
               @keydown.up="up"
               @keydown.enter="hit"
               @keydown.esc="reset"
               @blur="reset"
               @input="update"/>

        <!-- the list -->
        <ul v-show="hasItems">
            <li v-for="item in items" :class="activeClass($index)" @mousedown="hit" @mousemove="setActive($index)">
                <span class="name" v-text="item.name"></span>
            </li>
        </ul>
    </div>
</typeahead>

Options

template: Import template from separate file.

src: The source url.

data The data that would be sent by request.

limit: Limit the number of items which is shown at the list.

onHit: The callback function which is triggered when the user hits on an item.

prepareResponseData The callback function which is triggered when the response data are received.

Key Actions

Down Arrow: Highlight the previous item.

Up Arrow: Highlight the next item.

Enter: Hit on highlighted item.

Escape: Hide the list.

States

loading: Indicates that awaits the data.

isEmpty: Indicates that the input is empty.

isDirty: Indicates that the input is not empty.

Useful if you want to add icon indicators (see the demo)

License

VueTypeahead is released under the MIT License. See the bundled LICENSE file for details.

vue-typeahead's People

Contributors

pespantelis avatar simulatedgreg avatar matt-west avatar

Watchers

James Cloos avatar Abishek R Srikaanth avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.