File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div style =" position : relative "
3
- v-bind:class =" {'open':showDropdown}"
3
+ v-bind:class =" {'open':showDropdown}"
4
4
>
5
5
<input type =" text" class =" form-control"
6
6
:placeholder =" placeholder"
25
25
26
26
<script >
27
27
import {getJSON , coerce } from ' ./utils/utils.js'
28
+ import _ from ' lodash'
28
29
29
30
let Vue = window .Vue
30
31
31
32
export default {
32
33
created () {
33
34
this .items = this .primitiveData
35
+ this .debounceUpdate = _ .debounce (function (that ){
36
+ getJSON (that .async + that .value ).then (data => {
37
+ that .items = (that .key ? data[that .key ] : data).slice (0 , that .limit )
38
+ that .showDropdown = that .items .length > 0
39
+ })
40
+ }, this .debounce );
34
41
},
35
42
partials: {
36
- default: ' <span v-html="item | highlight query "></span>'
43
+ default: ' <span v-html="item | highlight value "></span>'
37
44
},
38
45
props: {
39
46
value: {
@@ -81,6 +88,11 @@ export default {
81
88
},
82
89
placeholder: {
83
90
type: String
91
+ },
92
+ debounce: {
93
+ type: Number ,
94
+ default: 100 ,
95
+ coerce: coerce .number
84
96
}
85
97
},
86
98
data () {
@@ -119,10 +131,7 @@ export default {
119
131
this .showDropdown = this .items .length > 0
120
132
}
121
133
if (this .async ) {
122
- getJSON (this .async + this .value ).then (data => {
123
- this .items = (this .key ? data[this .key ] : data).slice (0 , this .limit )
124
- this .showDropdown = this .items .length > 0
125
- })
134
+ this .debounceUpdate (this )
126
135
}
127
136
},
128
137
reset () {
You can’t perform that action at this time.
0 commit comments