🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

vue-suggestion

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-suggestion

Suggestion list input for Vue.js

1.0.0
Source
npm
Version published
Weekly downloads
480
-27.27%
Maintainers
1
Weekly downloads
 
Created
Source

vue-suggestion

Suggestion list input for Vue.js

In-action GIF

Useful Links

Table of Contents

Getting started

  • Install the plugin:

    npm install vue-suggestion
    
  • Add the plugin into your app:

    import Vue from 'vue'
    import VueSuggestion from 'vue-suggestion'
    
    Vue.use(VueSuggestion)
    

    More info on installation

  • Use the vue-suggestion component:

    <template>
      <vue-suggestion :items="items" 
                      v-model="item", 
                      :setLabel="setLabel",
                      :itemTemplate="itemTemplate", 
                      @changed="inputChange", 
                      @selected="itemSelected">
      </vue-suggestion>
    </template>
    
    <script>
    import itemTemplate from './item-template.vue';
    export default {
      data () {
        return {
          item: {},
          items: [
            { id: 1, name: 'Golden Retriever'},
            { id: 2, name: 'Cat'},
            { id: 3, name: 'Squirrel'},
          ],
          itemTemplate,
        }
      },
      methods: {
        itemSelected (item) {
          this.item = item;
        },
        setLabel (item) {
          return item.name;
        },
        inputChange (text) {
          // your search method
          this.items = items.filter(item => item.name.contains(text));
          // now `items` will be showed in the suggestion list
        },
      },
    };
    </script>
    

    ItemTemplate example:

    <template>
      <div>
        <b>#{{ item.id }}</b>
        <span>{{ item.name }}</span>
      </div>
    </template>
    
    <script>
    export default {
      props: {
        item: { required: true },
      }
    }
    </script>
    

Installation

npm

  npm install vue-suggestion

Install the plugin into Vue:

import Vue from 'vue'
import VueSuggestion from 'vue-suggestion'

Vue.use(VueSuggestion, [globalOptions = {}]) // Define default global options here (optional)

View all available options in Props.

Or use the component directly:

<!-- your-component.vue-->
<template>
  <vue-suggestion v-model="value"></vue-suggestion>
</template>
<script>
import { VueSuggestion } from 'vue-suggestion';

export default {
  components: {
    VueSuggestion,
  },
};
</script>

Browser

Include vue-suggestion in the page.

<script src="https://unpkg.com/vue-suggestion"></script>

If Vue is detected in the Page, the plugin is installed automatically.

Manually install the plugin into Vue:

Vue.use(VueSuggestion)

Or use the component directly:

Vue.component('vue-suggestion', VueSuggestion.VueSuggestion)

Usage

Props

PropertyTypeDefault valueDescription
itemTemplateVue componentTemplate for item in suggestion list
setLabelfunctionValue of chosen input, be shown in the input
itemsArray[]Suggestion array, should be updated dynamically after onInputChange()
minLenNumber2Minimum number of characters inputted to start searching
disabledBooleanfalseDisable the input
placeholderString''Placeholder of the input

Events

EventArgumentsDescription
changedStringFires when the input changes with the argument is the current input text.
selectedObjectFires when user selects a suggestion
enterObjectNative enter/return key press event
key-upObjectNative key up event
key-downObjectNative key down event
focusObjectNative focus event
blurObjectNative blur event

Slots

SlotDescription
searchSlotNext to the input, for the custom search icon or button...

Credits

made with ❤ by Steven.

Keywords

vue

FAQs

Package last updated on 22 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts