Autocomplete.vue 922 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <template>
  2. <span v-if="isLook">{{ select_look || '-' }}</span>
  3. <el-autocomplete
  4. v-else
  5. v-model="select"
  6. :value-key="field.label"
  7. :fetch-suggestions="querySearch"
  8. :disabled="disabled"
  9. />
  10. </template>
  11. <script setup lang="ts">
  12. import { useOptions } from '../hooks/useOptions'
  13. const props = defineProps({
  14. modelValue: {
  15. type: [String, Number, Array],
  16. default: () => ''
  17. },
  18. mode: {
  19. type: String,
  20. default: 'add'
  21. },
  22. formItem: {
  23. type: Object,
  24. default: () => {}
  25. },
  26. disabled: {
  27. type: Boolean,
  28. default: false
  29. }
  30. })
  31. const emits = defineEmits(['update:modelValue'])
  32. const { options, field, isLook, select, select_look } = useOptions(props, emits)
  33. const querySearch = (queryString, cb) => {
  34. const results = queryString ? options.filter((i) => i[field.label] === queryString) : options
  35. // 调用 callback 返回建议列表的数据
  36. cb(results)
  37. }
  38. </script>