index.vue 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template>
  2. <div @click="handlerClick">
  3. <el-autocomplete
  4. id="autocompleteId"
  5. ref="autocomplete"
  6. style="width: 100%"
  7. v-model="selectItem"
  8. :fetch-suggestions="querySearchAsync"
  9. placeholder=""
  10. :debounce="0"
  11. @select="handleSelect"
  12. ></el-autocomplete>
  13. </div>
  14. </template>
  15. <script>
  16. export default {
  17. props: {
  18. value: {
  19. type: [String, Number],
  20. default: ''
  21. },
  22. list: {
  23. type: Array,
  24. default: []
  25. }
  26. },
  27. data() {
  28. return {
  29. selectItem: this.value
  30. }
  31. },
  32. watch: {
  33. value(newValue) {
  34. this.selectItem = newValue
  35. }
  36. },
  37. methods: {
  38. handlerClick() {
  39. this.$emit('click')
  40. },
  41. handleSelect(value) {
  42. this.selectItem = value.value
  43. this.$emit('input', this.selectItem)
  44. this.$emit('change', value)
  45. },
  46. async querySearchAsync(queryString, cb) {
  47. let data = this.list.filter(item => ~item.value.indexOf(queryString)).slice(0, 100)
  48. cb(data)
  49. }
  50. }
  51. }
  52. </script>
  53. <style></style>