VInput.vue 1.25 KB
<template>
    <!--
    二次封装:
    - 统一样式类 v-input
    - 支持 block(全宽)
  -->
    <ElInput class="v-input"
             :class="[{ 'v-input--block': !!props.block }]"
             :clearable="props.clearable"
             :disabled="props.disabled"
             :model-value="props.modelValue"
             :placeholder="props.placeholder"
             :type="props.type"
             v-bind="$attrs"
             @update:model-value="emit('update:modelValue', $event)">
        <template #prepend>
            <slot name="prepend" />
        </template>
        <template #append>
            <slot name="append" />
        </template>
        <template #prefix>
            <slot name="prefix" />
        </template>
        <template #suffix>
            <slot name="suffix" />
        </template>
    </ElInput>
</template>

<script setup lang="ts">
import { ElInput } from "element-plus";

const props = defineProps<{
	block?: boolean;
	clearable?: boolean;
	disabled?: boolean;
	modelValue?: number | string;
	placeholder?: string;
	type?: string;
}>();

const emit = defineEmits([ "update:modelValue" ]);
</script>

<style scoped>
.v-input {
	/* 可以在此定制输入框的默认样式 */
}

.v-input--block {
	display: block;
}
</style>