|
| 1 | +# Vue 2 Autocomplete |
| 2 | +Autocomplete Component For [Vue 2](http://vuejs.org). It's based on [vue-autocomplete](https://github.com/BosNaufal/vue-autocomplete) |
| 3 | + |
| 4 | +<p align="center"> |
| 5 | + <a href="./" title="Vue Autocomplete"> |
| 6 | + <img src="./demo.gif" alt="vue Autocomplete component" title="Vue Autocomplete Component"/> |
| 7 | + </a> |
| 8 | +</p> |
| 9 | + |
| 10 | +## Install |
| 11 | +You can import [vue2-autocomplete.vue](./src/js/components/vue-autocomplete.vue) to your vue component file like [this](./src/js/components/app.vue) and process it with your preprocessor. |
| 12 | + |
| 13 | +You can install it via NPM |
| 14 | +```bash |
| 15 | +npm install vue2-autocomplete-js |
| 16 | +``` |
| 17 | + |
| 18 | +Or Just put it after Vue JS~ |
| 19 | +```html |
| 20 | +<script src="https://vuejs.org/js/vue.min.js"></script> |
| 21 | +<script src="./dist/vue2-autocomplete.js"></script> |
| 22 | +<script> |
| 23 | + // Don't Forget to register it |
| 24 | + new Vue({ |
| 25 | + components: { |
| 26 | + autocomplete: Vue2Autocomplete |
| 27 | + } |
| 28 | + }); |
| 29 | +</script> |
| 30 | +``` |
| 31 | + |
| 32 | +## Import Style |
| 33 | +Don't forget to import vue 2 css. You can link it via html |
| 34 | +```html |
| 35 | +<link rel="stylesheet" href="vue2-autocomplete/dist/style/vue2-autocomplete.css"> |
| 36 | +``` |
| 37 | + |
| 38 | +Or You can import it using commonJS |
| 39 | + |
| 40 | +```javascript |
| 41 | +require('vue2-autocomplete-js/style/vue2-autocomplete.css') |
| 42 | +``` |
| 43 | + |
| 44 | +Its style is very customizable. You can put any CSS over it. And You can add custom class via its prop. |
| 45 | + |
| 46 | + |
| 47 | +## Import Module |
| 48 | +```javascript |
| 49 | +import Autocomplete from 'vue2-autocomplete-js' |
| 50 | +// Or |
| 51 | +var Autocomplete = require('vue2-autocomplete-js'); |
| 52 | +``` |
| 53 | + |
| 54 | +## Usage |
| 55 | +```html |
| 56 | +<template> |
| 57 | + |
| 58 | + <autocomplete |
| 59 | + url="http://localhost/proyek/goodmovie/api/api/v1/search" |
| 60 | + anchor="title" |
| 61 | + label="writer" |
| 62 | + :on-select="getData"> |
| 63 | + </autocomplete> |
| 64 | + |
| 65 | +</template> |
| 66 | + |
| 67 | + |
| 68 | +<script> |
| 69 | +
|
| 70 | + import Autocomplete from 'vue2-autocomplete-js'; |
| 71 | +
|
| 72 | + export default { |
| 73 | +
|
| 74 | + components: { Autocomplete }, |
| 75 | +
|
| 76 | + methods: { |
| 77 | + getFiles(obj){ |
| 78 | + console.log(obj); |
| 79 | + } |
| 80 | + } |
| 81 | + }; |
| 82 | +
|
| 83 | +</script> |
| 84 | +``` |
| 85 | + |
| 86 | +Full Props |
| 87 | +```html |
| 88 | +<template> |
| 89 | + |
| 90 | + <autocomplete |
| 91 | + url="http://localhost/proyek/goodmovie/api/api/v1/search" |
| 92 | + anchor="title" |
| 93 | + label="writer" |
| 94 | + :on-select="getData" |
| 95 | + |
| 96 | + id="custom id" |
| 97 | + class-name="custom class name" |
| 98 | + placeholder="placeholder" |
| 99 | + :init-value="initial value" |
| 100 | + :init-value="initial value" |
| 101 | + :custom-params="{ token: 'dev' }" |
| 102 | + :min="3" |
| 103 | + |
| 104 | + :on-input="callbackEvent" |
| 105 | + :on-show="callbackEvent" |
| 106 | + :on-blur="callbackEvent" |
| 107 | + :on-hide="callbackEvent" |
| 108 | + :on-focus="callbackEvent" |
| 109 | + :on-select="callbackEvent" |
| 110 | + :on-before-ajax="callbackEvent" |
| 111 | + :on-ajax-progress="callbackEvent" |
| 112 | + :on-ajax-loaded="callbackEvent"> |
| 113 | + </autocomplete> |
| 114 | + |
| 115 | +</template> |
| 116 | +``` |
| 117 | + |
| 118 | +## Props |
| 119 | +#### url* (String) |
| 120 | +the URL must be active (not from file). the component will fetch JSON from this URL and passing one params (default : `q`) query. like: |
| 121 | +``` |
| 122 | +http://some-url.com/API/list?q= |
| 123 | +``` |
| 124 | +There are no filter and limit action inside the component. So, do it in your API logic. |
| 125 | + |
| 126 | + |
| 127 | +#### params (String) |
| 128 | +name of the search parameter to query in Ajax call. default is `q=` |
| 129 | + |
| 130 | + |
| 131 | +#### min (Number) |
| 132 | +Minimum input typed chars before performing the search query. default is `0` |
| 133 | + |
| 134 | + |
| 135 | +#### anchor* (String) |
| 136 | +It's a object property name that passed by your API. It's used for Anchor in suggestions list. Example `anchor="name"` will get the name property of your JSON object. Like ("Bambang", "Sukijan", "Bejo") in the demo above. |
| 137 | + |
| 138 | + |
| 139 | +#### label (String) |
| 140 | +Same as anchor but it's used for subtitle or description of list |
| 141 | + |
| 142 | + |
| 143 | +#### placeholder (String) |
| 144 | +Placeholder for input |
| 145 | + |
| 146 | +#### className (String) |
| 147 | +Custom class name for autocomplete component |
| 148 | + |
| 149 | +#### id (String) |
| 150 | +Custom id name for autocomplete component |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | +## Callback Events |
| 155 | +You can make a callback event via props. |
| 156 | + |
| 157 | +#### onInput (Function) |
| 158 | +On Input event in autocomplete |
| 159 | + |
| 160 | +#### onShow (Function) |
| 161 | +On Show event in autocomplete list |
| 162 | + |
| 163 | +#### onBlur (Function) |
| 164 | +When autocomplete is blured |
| 165 | + |
| 166 | +#### onHide (Function) |
| 167 | +When autocomplete list is hidden |
| 168 | + |
| 169 | +#### onFocus (Function) |
| 170 | +When autocomplete input in focus mode |
| 171 | + |
| 172 | +#### onSelect (Function) |
| 173 | +When user has selected one item in the list |
| 174 | + |
| 175 | +#### onBeforeAjax (Function) |
| 176 | +Before the ajax send |
| 177 | + |
| 178 | +#### onAjaxProgress (Function) |
| 179 | +While ajax is fetching the data |
| 180 | + |
| 181 | +#### onAjaxLoaded (Function) |
| 182 | +When ajax process is totally loaded |
| 183 | + |
| 184 | + |
| 185 | +## Methods |
| 186 | +You can do some methods by accessing the component via javascript. |
| 187 | +```javascript |
| 188 | +this.$refs.autocomplete.someMethod() |
| 189 | +``` |
| 190 | + |
| 191 | +#### setValue (String) |
| 192 | +To set the value of the autocomplete input |
| 193 | + |
| 194 | + |
| 195 | + |
| 196 | +## Thank You for Making this useful~ |
| 197 | + |
| 198 | +## Let's talk about some projects with me |
| 199 | +Just Contact Me At: |
| 200 | +- Email: [bosnaufalemail@gmail.com](mailto:bosnaufalemail@gmail.com) |
| 201 | +- Skype Id: bosnaufal254 |
| 202 | +- twitter: [@BosNaufal](https://twitter.com/BosNaufal) |
| 203 | + |
| 204 | +## License |
| 205 | +[MIT](http://opensource.org/licenses/MIT) |
| 206 | +Copyright (c) 2016 - forever Naufal Rabbani |
0 commit comments