input.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <div class="ui-input">
  3. <template v-if="type">
  4. <component :is="InputComponents[type].component" v-bind="childProps" :modelValue="props.modelValue" @update:model-value="newValue => emit('update:modelValue', newValue)">
  5. <template v-for="(slot, name) in $slots" #[name]="raw">
  6. <slot :name="name" v-bind="raw"></slot>
  7. </template>
  8. </component>
  9. <slot></slot>
  10. <!-- <p class="error-msg" v-if="error">{{ error }}</p> -->
  11. </template>
  12. </div>
  13. </template>
  14. <script setup lang="ts">
  15. import { computed } from 'vue'
  16. import { inputProps, InputComponents } from './input'
  17. const props = defineProps(inputProps)
  18. console.log('props', props)
  19. // const emit = defineEmits(['update:modelValue'])
  20. // const type = computed(() => (types[props.type] ? props.type : 'text'))
  21. const childProps = computed(() => {
  22. if (props.type) {
  23. console.log('props--type', InputComponents[props.type])
  24. return InputComponents[props.type].props
  25. }
  26. // const retain = Object.keys(types[type.value].propsDesc)
  27. // const childProps = {}
  28. // for (let key in props) {
  29. // if (retain.includes(key)) {
  30. // childProps[key] = props[key]
  31. // }
  32. // }
  33. // if (!types[props.type]) {
  34. // childProps.type = props.type
  35. // }
  36. // return childProps
  37. return false
  38. })
  39. // const style = computed(() => {
  40. // const style = {}
  41. // const keys = Object.keys(childProps.value)
  42. // if (!keys.includes('width')) {
  43. // style.width = props.width
  44. // }
  45. // if (!keys.includes('height')) {
  46. // style.height = props.height
  47. // }
  48. // return style
  49. // })
  50. </script>