---
title: "AsPhoneNumberInput"
description: "带输入掩码格式化的电话号码输入框组件。"
seo_title: "AsPhoneNumberInput"
seo_description: "A phone number input with mask formatting and dial-code support, built on the Nuxt UI input."
canonical_url: "https://nuxt.mhaibaraai.cn/docs/components/as-phone-number-input"
---
# AsPhoneNumberInput

> 带输入掩码格式化的电话号码输入框组件。

## 简介

`MAsPhoneNumberInput` 是一个电话号码输入框组件，通过输入掩码自动格式化号码，支持自定义掩码和区号前缀展示。

> \[\!NOTE\]
> See: https://ui.nuxt.com/docs/components/input
> 
> 基于 Nuxt UI 的 Input 组件封装，使用 
> 
> maska
> 
>  处理输入掩码

## 用法

`#` 代表数字占位符，默认掩码为 `### #### ####`、区号为 `+86`（中国大陆格式）。

```vue
<script setup lang="ts">
const value = ref("")
</script>

<template>
  <MAsPhoneNumberInput />
</template>
```

### `dialCode` 区号

通过 `dialCode` 在输入框前展示国家或地区区号：

```vue
<template>
  <MAsPhoneNumberInput dial-code="+1" />
</template>
```

### `mask` 掩码

通过 `mask` 适配不同国家的号码格式，`#` 代表数字占位符：

```vue
<template>
  <MAsPhoneNumberInput mask="(###) ###-####" />
</template>
```

## 示例

### 融入`UFieldGroup`

与按钮置于 `UFieldGroup` 时共用尺寸、圆角和边框衔接，适合组合拨号操作：

```vue
<template>
  <UFieldGroup size="xs">
    <MAsPhoneNumberInput dial-code="+1" />
    <UButton icon="i-lucide-phone-call" color="neutral" variant="subtle" />
  </UFieldGroup>
</template>
```

## API

### Props

```ts
/**
 * Props for the MAsPhoneNumberInput component
 */
interface MAsPhoneNumberInputProps {
  /**
   * 输入掩码格式，`#` 表示一个数字位。
   * @default "\"(###) ###-####\""
   */
  mask?: string | undefined;
  /**
   * 区号前缀
   * @default "\"+86\""
   */
  dialCode?: string | undefined;
  ui?: (Record<string, C> & { root?: SlotClass; base?: SlotClass; leading?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailing?: SlotClass; trailingIcon?: SlotClass; dialCode?: SlotClass; }) | undefined;
  /**
   * The element or component this component should render as.
   */
  as?: any;
  id?: string | undefined;
  name?: string | undefined;
  /**
   * The placeholder text when the input is empty.
   */
  placeholder?: string | undefined;
  color?: "primary" | "secondary" | "info" | "success" | "warning" | "error" | "important" | "neutral" | undefined;
  variant?: "outline" | "soft" | "subtle" | "ghost" | "none" | undefined;
  size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
  required?: boolean | undefined;
  autocomplete?: "on" | "off" | (string & {}) | undefined;
  autofocus?: boolean | undefined;
  autofocusDelay?: number | undefined;
  disabled?: boolean | undefined;
  /**
   * Highlight the ring color like a focus state.
   */
  highlight?: boolean | undefined;
  /**
   * Keep the mobile text size on all breakpoints.
   */
  fixed?: boolean | undefined;
  defaultValue?: T | undefined;
  modelModifiers?: ModelModifiers | undefined;
  /**
   * Display an icon based on the `leading` and `trailing` props.
   */
  icon?: any;
  /**
   * Display an avatar on the left side.
   */
  avatar?: AvatarProps | undefined;
  /**
   * When `true`, the icon will be displayed on the left side.
   */
  leading?: boolean | undefined;
  /**
   * Display an icon on the left side.
   */
  leadingIcon?: any;
  /**
   * When `true`, the icon will be displayed on the right side.
   */
  trailing?: boolean | undefined;
  /**
   * Display an icon on the right side.
   */
  trailingIcon?: any;
  /**
   * When `true`, the loading icon will be displayed.
   */
  loading?: boolean | undefined;
  /**
   * The icon when the `loading` prop is `true`.
   */
  loadingIcon?: any;
  enterKeyHint?: "enter" | "done" | "go" | "next" | "previous" | "search" | "send" | undefined;
  form?: string | undefined;
  formaction?: string | undefined;
  formenctype?: string | undefined;
  formmethod?: string | undefined;
  formnovalidate?: Booleanish | undefined;
  formtarget?: string | undefined;
  list?: string | undefined;
  max?: Numberish | undefined;
  maxlength?: Numberish | undefined;
  min?: Numberish | undefined;
  minlength?: Numberish | undefined;
  pattern?: string | undefined;
  readonly?: Booleanish | undefined;
  step?: Numberish | undefined;
  modelValue?: T | undefined;
}
```

### Emits

```ts
/**
 * Emitted events for the MAsPhoneNumberInput component
 */
interface MAsPhoneNumberInputEmits {
  update:modelValue: (payload: [value: T]) => void;
  blur: (payload: [event: FocusEvent]) => void;
  change: (payload: [event: Event]) => void;
  update:modelValue: (payload: [value: T | undefined]) => void;
}
```

### Slots

```ts
/**
 * Slots for the MAsPhoneNumberInput component
 */
interface MAsPhoneNumberInputSlots {
  default(): any;
  trailing(): any;
}
```

## Theme

<component-theme></component-theme>## Changelog

See commit history for [src/runtime/components/input/AsPhoneNumberInput.vue](https://github.com/mhaibaraai/movk-nuxt/commits/main/src/runtime/components/input/AsPhoneNumberInput.vue).


## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
