AsPhoneNumberInput
简介
MAsPhoneNumberInput 是一个电话号码输入框组件,通过输入掩码自动格式化号码,支持自定义掩码和区号前缀展示。
用法
# 代表数字占位符,默认掩码为 ### #### ####、区号为 +86(中国大陆格式)。
<script setup lang="ts">
const value = ref("")
</script>
<template>
<MAsPhoneNumberInput v-model="value" />
</template>
dialCode 区号
通过 dialCode 在输入框前展示国家或地区区号:
<template>
<MAsPhoneNumberInput dial-code="+1" />
</template>
mask 掩码
通过 mask 适配不同国家的号码格式,# 代表数字占位符:
<template>
<MAsPhoneNumberInput mask="(###) ###-####" />
</template>
示例
融入UFieldGroup
与按钮置于 UFieldGroup 时共用尺寸、圆角和边框衔接,适合组合拨号操作:
<template>
<UFieldGroup size="xs">
<MAsPhoneNumberInput dial-code="+1" />
<UButton icon="i-lucide-phone-call" color="neutral" variant="subtle" />
</UFieldGroup>
</template>
API
Props
| Prop | Default | Type |
|---|---|---|
as | 'div' | anyThe element or component this component should render as. |
mask | '(###) ###-####' | string输入掩码格式, |
dialCode | '+86' | string区号前缀 |
id | string | |
name | string | |
placeholder | stringThe placeholder text when the input is empty. | |
color | 'primary' | "primary" | "secondary" | "info" | "success" | "warning" | "error" | "important" | "neutral" |
variant | 'outline' | "outline" | "soft" | "subtle" | "ghost" | "none" |
size | 'md' | "xs" | "sm" | "md" | "lg" | "xl" |
autocomplete | "on" | "off" | string & {} | |
autofocusDelay | number | |
defaultValue | T | |
modelModifiers | ModelModifiers | |
icon | anyDisplay an icon based on the | |
avatar | AvatarPropsDisplay an avatar on the left side. | |
leadingIcon | anyDisplay an icon on the left side. | |
trailingIcon | anyDisplay an icon on the right side. | |
loadingIcon | appConfig.ui.icons.loading | anyThe icon when the |
list | string | |
max | string | number | |
maxlength | string | number | |
min | string | number | |
minlength | string | number | |
pattern | string | |
readonly | false | true | "true" | "false" | |
step | string | number | |
modelValue | T | |
required | boolean | |
autofocus | boolean | |
disabled | boolean | |
highlight | booleanHighlight the ring color like a focus state. | |
fixed | booleanKeep the mobile text size on all breakpoints. | |
leading | booleanWhen | |
trailing | booleanWhen | |
loading | booleanWhen | |
ui | Record<string, ClassNameValue> & { root?: SlotClass; base?: SlotClass; leading?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailing?: SlotClass; trailingIcon?: SlotClass; dialCode?: SlotClass; } |
Emits
| Event | Type |
|---|---|
update:modelValue | [value: T] |
blur | [event: FocusEvent] |
change | [event: Event] |
Slots
| Slot | Type |
|---|---|
default | { ui: { root: (props?: Record<string, any>) => string; base: (props?: Record<string, any>) => string; leading: (props?: Record<string, any>) => string; leadingIcon: (props?: Record<string, any>) => string; leadingAvatar: (props?: Record<string, any>) => string; leadingAvatarSize: (props?: Record<string, any>) => string; trailing: (props?: Record<string, any>) => string; trailingIcon: (props?: Record<string, any>) => string; }; } |
trailing | { ui: { root: (props?: Record<string, any>) => string; base: (props?: Record<string, any>) => string; leading: (props?: Record<string, any>) => string; leadingIcon: (props?: Record<string, any>) => string; leadingAvatar: (props?: Record<string, any>) => string; leadingAvatarSize: (props?: Record<string, any>) => string; trailing: (props?: Record<string, any>) => string; trailingIcon: (props?: Record<string, any>) => string; }; } |
Theme
export default defineAppConfig({
ui: {
asPhoneNumberInput: {
slots: {
base: '',
leading: '',
dialCode: ''
},
variants: {
dialCode: {
true: {
base: 'ps-(--dial-code-length)',
leading: 'pointer-events-none text-muted'
}
}
}
}
}
})