---
title: "WithPasswordToggle"
description: "带显示/隐藏切换的密码输入框组件。"
seo_title: "WithPasswordToggle"
seo_description: "A password input with a show/hide visibility toggle, built on the Nuxt UI input."
canonical_url: "https://nuxt.mhaibaraai.cn/docs/components/with-password-toggle"
---
# WithPasswordToggle

> 带显示/隐藏切换的密码输入框组件。

## 简介

`MWithPasswordToggle` 是一个带有显示/隐藏切换功能的密码输入框组件。提供眼睛图标按钮，点击可在明文和密文之间切换显示，提升密码输入的用户体验。

> \[\!NOTE\]
> See: https://ui.nuxt.com/docs/components/input
> 
> 基于 Nuxt UI 的 Input 组件封装

## 用法

右侧眼睛按钮在明文与密文间切换：

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

<template>
  <MWithPasswordToggle />
</template>
```

### `leadingIcon` 前置图标

通过 `leadingIcon` 为密码框添加语义化图标：

```vue
<template>
  <MWithPasswordToggle leading-icon="i-lucide-lock" />
</template>
```

### `size` 尺寸

通过 `size` 切换输入框与按钮尺寸：

```vue
<template>
  <MWithPasswordToggle v-model="value" size="md" />
</template>
```

### `buttonProps` 切换按钮

通过 `buttonProps` 自定义切换按钮样式：

```vue
<template>
  <MWithPasswordToggle v-model="value" :button-props='{"color":"primary","variant":"soft"}' />
</template>
```

## API

### Props

```ts
/**
 * Props for the MWithPasswordToggle component
 */
interface MWithPasswordToggleProps {
  buttonProps?: ButtonProps | undefined;
  ui?: (Record<string, C> & { root?: SlotClass; base?: SlotClass; leading?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailing?: SlotClass; trailingIcon?: 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 MWithPasswordToggle component
 */
interface MWithPasswordToggleEmits {
  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 MWithPasswordToggle component
 */
interface MWithPasswordToggleSlots {
  leading(): any;
  default(): any;
}
```

## Theme

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

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


## Sitemap

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