Input 输入框
通过鼠标或键盘输入字符
DANGER
Input 为受控组件, 它 总会显示 Vue 绑定值。
在正常情况下, input
的输入事件应该被正常响应。它的处理程序应该更新组件的绑定值 (或使用 v-model
)。否则, 输入框的值将不会改变。
基础用法
<template>
<px-input v-model="input" style="width: 240px" placeholder="Please input" />
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const input = ref('')
</script>
禁用状态
通过 disabled
属性设置禁用状态
<template>
<px-input
v-model="input"
style="width: 240px"
disabled
placeholder="Please input"
/>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const input = ref('')
</script>
一键清空
使用 clearable
属性即可得到一个可一键清空的输入框
<template>
<px-input
v-model="input"
style="width: 240px"
placeholder="Please input"
clearable
/>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const input = ref('')
</script>
密码框
使用 showPassword
属性即可得到一个可切换显示隐藏的密码框
<template>
<px-input
v-model="input"
type="password"
placeholder="Please input password"
show-password
/>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const input = ref('')
</script>
带图标的输入框
带有图标标记输入类型
要在输入框中添加图标, 可通过 prefix
和 suffix
具名插槽来实现。
<template>
<div class="flex gap-4">
<px-text size="12">Using Slots</px-text>
<px-input v-model="input1" style="width: 240px" placeholder="Pick a date">
<template #suffix>
<px-icon icon="calender-solid" />
</template>
</px-input>
<px-input
v-model="input2"
style="width: 240px"
placeholder="Type something"
>
<template #prefix>
<px-icon icon="search" />
</template>
</px-input>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const input1 = ref('')
const input2 = ref('')
</script>
文本域
用于输入多行文本信息可缩放的输入框。添加 type="textarea"
属性来将 input
元素转换为原生的 textarea
元素。
文本域高度可通过 rows
属性控制
<template>
<px-input
v-model="textarea"
style="width: 240px"
:rows="2"
type="textarea"
placeholder="Please input"
/>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const textarea = ref('')
</script>
复合型输入框
可以在输入框中前置或后置一个元素, 通常是标签或按钮。
可通过 slot
来指定在 Input 中分发的前置或者后置的内容。
WARNING
待 px-select
组件开发完成后补充
<template>
<div>
<px-input
v-model="input1"
style="max-width: 600px"
placeholder="Please input"
>
<template #prepend>Http://</template>
</px-input>
</div>
<div class="mt-4">
<px-input
v-model="input2"
style="max-width: 600px"
placeholder="Please input"
>
<template #append>.com</template>
</px-input>
</div>
<div class="mt-4">
<px-input
v-model="input3"
style="max-width: 600px"
placeholder="Please input"
class="input-with-select"
>
<template #prepend>
<px-select v-model="select" placeholder="Select" style="width: 115px">
<px-option label="Restaurant" value="1" />
<px-option label="Order No." value="2" />
<px-option label="Tel" value="3" />
</px-select>
</template>
<template #append>
<px-button icon="search" />
</template>
</px-input>
</div>
<div class="mt-4">
<px-input
v-model="input3"
style="max-width: 600px"
placeholder="Please input"
class="input-with-select"
>
<template #prepend>
<px-button icon="search" />
</template>
<template #append>
<px-select v-model="select" placeholder="Select" style="width: 115px">
<px-option label="Restaurant" value="1" />
<px-option label="Order No." value="2" />
<px-option label="Tel" value="3" />
</px-select>
</template>
</px-input>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const input1 = ref('')
const input2 = ref('')
const input3 = ref('')
const select = ref('')
</script>
<style>
.input-with-select .px-input__append,
.input-with-select .px-input__prepend {
padding: 0;
margin: 0;
}
</style>
尺寸
通过 size
属性设置 Input 的尺寸。
<template>
<div class="flex items-center gap-8 mb-8">
<px-input
v-model="input1"
style="width: 240px"
size="large"
placeholder="Please Input"
/>
<px-input
v-model="input2"
style="width: 240px"
placeholder="Please Input"
/>
<px-input
v-model="input3"
style="width: 240px"
size="small"
placeholder="Please Input"
/>
</div>
<div class="flex items-center gap-8 mb-8">
<px-input
v-model="input1"
style="width: 240px"
size="large"
placeholder="Please Input"
/>
<px-input
v-model="input2"
style="width: 240px"
placeholder="Please Input"
/>
<px-input
v-model="input3"
style="width: 240px"
size="small"
placeholder="Please Input"
/>
</div>
<div class="flex items-center gap-8">
<px-input
v-model="input1"
style="width: 240px"
size="large"
placeholder="Please Input"
/>
<px-input
v-model="input2"
style="width: 240px"
placeholder="Please Input"
/>
<px-input
v-model="input3"
style="width: 240px"
size="small"
placeholder="Please Input"
/>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const input1 = ref('')
const input2 = ref('')
const input3 = ref('')
</script>
API_Table插件测试
DANGER
该插件基于 markdown-it
开发, 解析组件 types.ts
文件生成 API 表格, 测试中
Input API
Props
Name | Description | Type | Default |
---|---|---|---|
id | 输入框唯一标识 | string | - |
modelValue | 输入框绑定值 | string | - |
type | 输入框类型 | string | text |
size | 输入框尺寸 | enum | default |
disabled | 是否禁用 | boolean | false |
clearable | 是否显示清除按钮 | boolean | false |
showPassword | 是否显示切换密码图标 | boolean | false |
placeholder | 输入框占位符 | string | - |
readonly | 原生readonly 属性, 是否只读 | boolean | false |
autocomplete | 原生autocomplete 属性 | string | off |
autofocus | 原生autofocus 属性, 是否自动获取焦点 | boolean | false |
form | 原生form 属性, 指定输入框所属的表单 | string | - |
Events
Name | Description | Type |
---|---|---|
update:modelValue | 输入框值改变时触发 | function |
input | 在 Input 值改变时触发 | function |
change | 仅当 modelValue 改变时, 当输入框失去焦点或用户按 Enter 时触发 | function |
focus | 输入框获得焦点时触发 | function |
blur | 输入框失去焦点时触发 | function |
clear | 点击清除按钮时触发 | function |
Slots
Name | Description |
---|---|
prefix | 输入框头部内容 |
suffix | 输入框尾部内容 |
prepend | 输入框前置内容 |
append | 输入框后置内容 |
Expose
Name | Description | Type |
---|---|---|
ref | 获取原生输入框元素 | object |
focus | 获取焦点 | function |
blur | 失去焦点 | function |
select | 选中输入框内容 | function |
clear | 清空输入框内容 | function |