InputCom.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <view class="ic-input-box" :style="style">
  3. <text class="title" :style="textStyle">{{ title }}</text>
  4. <input
  5. ref="inputRef"
  6. class="input"
  7. :value="inputContent"
  8. placeholder="请输入"
  9. placeholder-style="color: rgb(136,136,136)"
  10. @input="handleInput"
  11. />
  12. </view>
  13. </template>
  14. <script lang="ts" setup>
  15. import { ref, watch } from 'vue'
  16. interface Props {
  17. title: string
  18. type: string
  19. defaultValue?: string
  20. style?: any
  21. textStyle?: any
  22. }
  23. const props = withDefaults(defineProps<Props>(), {
  24. defaultValue: '',
  25. })
  26. const emit = defineEmits<{
  27. change: [text: string, type: string]
  28. }>()
  29. const inputContent = ref(props.defaultValue)
  30. const inputRef = ref<any>(null)
  31. // 暴露方法
  32. defineExpose({
  33. reset: () => {
  34. inputContent.value = ''
  35. },
  36. inputContent: inputContent.value,
  37. })
  38. // 处理输入
  39. const handleInput = (e: any) => {
  40. const text = e.detail.value
  41. inputContent.value = text
  42. emit('change', text, props.type)
  43. }
  44. </script>
  45. <style lang="scss" scoped>
  46. .ic-input-box {
  47. display: flex;
  48. flex-direction: row;
  49. flex-wrap: nowrap;
  50. align-items: center;
  51. margin-bottom: 10px;
  52. margin-left: 5px;
  53. }
  54. .title {
  55. width: 60px;
  56. font-size: 12px;
  57. color: rgb(51, 51, 51);
  58. text-align: right;
  59. }
  60. .input {
  61. flex: 1;
  62. height: 30px;
  63. padding: 0 5px;
  64. font-size: 12px;
  65. color: rgba(136, 136, 136, 1);
  66. border: 1px solid #ccc;
  67. border-radius: 6px;
  68. }
  69. </style>