Input输入框
Input 输入框
通过鼠标或键盘输入内容,是最基础的表单域的包装。
何时使用
-
需要用户输入表单域内容时。
-
提供组合型输入框,带搜索的输入框,还可以进行大小选择。
代码演示
基本用法
基本用法。
<template> <a-input v-model:value="value" placeholder="Basic usage" /></template><script lang="ts">import { defineComponent, ref } from 'vue';export default defineComponent({ setup() { const value = ref<string>(''); return { value, }; },});</script>
前缀和后缀
在输入框上添加前缀或后缀图标。
<template> <div class="components-input-demo-presuffix"> <a-input placeholder="Basic usage" v-model:value="userName"> <template #prefix> <user-outlined type="user" /> </template> <template #suffix> <a-tooltip title="Extra information"> <info-circle-outlined style="color: rgba(0, 0, 0, 0.45)" /> </a-tooltip> </template> </a-input> <br /> <br /> <a-input prefix="¥" suffix="RMB" /> </div></template><script lang="ts">import { UserOutlined, InfoCircleOutlined } from '@ant-design/icons-vue';import { defineComponent, ref } from 'vue';export default defineComponent({ components: { UserOutlined, InfoCircleOutlined, }, setup() { const userName = ref<string>(''); return { userName, }; },});</script>
搜索框 loading
用于 onSearch 的时候展示 loading。
<template> <div> <a-input-search v-model:value="value" placeholder="input search loading deault" loading /> <br /> <br /> <a-input-search v-model:value="value" placeholder="input search loading with enterButton" loading enter-button /> </div></template><script lang="ts">import { defineComponent, ref } from 'vue';export default defineComponent({ setup() { const value = ref<string>(''); return { value, }; },});</script>
输入框组合
输入框的组合展现。 注意:使用 compact 模式时,不需要通过 Col 来控制宽度。
<template> <div> <a-input-group size="large"> <a-row :gutter="8"> <a-col :span="5"> <a-input v-model:value="value1" /> </a-col> <a-col :span="8"> <a-input v-model:value="value2" /> </a-col> </a-row> </a-input-group> <br /> <a-input-group compact> <a-input style="width: 20%" v-model:value="value1" /> <a-input style="width: 30%" v-model:value="value2" /> </a-input-group> <br /> <a-input-group compact> <a-select v-model:value="value3"> <a-select-option value="Zhejiang">Zhejiang</a-select-option> <a-select-option value="Jiangsu">Jiangsu</a-select-option> </a-select> <a-input style="width: 50%" v-model:value="value4" /> </a-input-group> <br /> <a-input-group compact> <a-select v-model:value="value5"> <a-select-option value="Option1">Option1</a-select-option> <a-select-option value="Option2">Option2</a-select-option> </a-select> <a-input style="width: 50%" v-model:value="value6" /> </a-input-group> <br /> <a-input-group compact> <a-input style="width: 50%" v-model:value="value7" /> <a-date-picker v-model:value="value8" style="width: 50%" /> </a-input-group> <br /> <a-input-group compact> <a-select v-model:value="value9"> <a-select-option value="Option1-1">Option1-1</a-select-option> <a-select-option value="Option1-2">Option1-2</a-select-option> </a-select> <a-select v-model:value="value10"> <a-select-option value="Option2-1">Option2-1</a-select-option> <a-select-option value="Option2-2">Option2-2</a-select-option> </a-select> </a-input-group> <br /> <a-input-group compact> <a-select v-model:value="value11"> <a-select-option value="1">Between</a-select-option> <a-select-option value="2">Except</a-select-option> </a-select> <a-input v-model:value="value12" style="width: 100px; text-align: center" placeholder="Minimum" /> <a-input v-model:value="value13" style="width: 30px; border-left: 0; pointer-events: none; backgroundcolor: #fff" placeholder="~" disabled /> <a-input v-model:value="value14" style="width: 100px; text-align: center; border-left: 0" placeholder="Maximum" /> </a-input-group> <br /> <a-input-group compact> <a-select v-model:value="value15"> <a-select-option value="Sign Up">Sign Up</a-select-option> <a-select-option value="Sign In">Sign In</a-select-option> </a-select> <a-auto-complete v-model:value="value16" :data-source="dataSource" style="width: 200px" placeholder="Email" /> </a-input-group> <br /> <a-input-group compact> <a-select v-model:value="value17" style="width: 30%"> <a-select-option value="Home">Home</a-select-option> <a-select-option value="Company">Company</a-select-option> </a-select> <a-cascader v-model:value="value18" style="width: 70%" :options="options" placeholder="Select Address" /> </a-input-group> </div></template><script lang="ts">import { defineComponent, ref, watch } from 'vue';const options = [ { value: 'zhejiang', label: 'Zhejiang', children: [ { value: 'hangzhou', label: 'Hangzhou', children: [ { value: 'xihu', label: 'West Lake', }, ], }, ], }, { value: 'jiangsu', label: 'Jiangsu', children: [ { value: 'nanjing', label: 'Nanjing', children: [ { value: 'zhonghuamen', label: 'Zhong Hua Men', }, ], }, ], },];export default defineComponent({ setup() { const value1 = ref<string>('0571'); const value2 = ref<string>('26888888'); const value3 = ref<string>('Zhejiang'); const value4 = ref<string>('Xihu District, Hangzhou'); const value5 = ref<string>('Option1'); const value6 = ref<string>('input content'); const value7 = ref<string>('input content'); const value8 = ref<string | null>(null); const value9 = ref<string>('Option1-1'); const value10 = ref<string>('Option2-2'); const value11 = ref<string>('1'); const value12 = ref<string>(''); const value13 = ref<string>(''); const value14 = ref<string>(''); const value15 = ref<string>('Sign Up'); const value16 = ref<string>(''); const value17 = ref<string>('Home'); const value18 = ref<string[]>([]); const dataSource = ref<string[]>([]); watch(value16, val => { dataSource.value = !val || val.indexOf('@') >= 0 ? [] : [`${val}@gmail.com`, `${val}@163.com`, `${val}@qq.com`]; }); return { value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11, value12, value13, value14, value15, value16, value17, value18, options, dataSource, }; },});</script>
输入时格式化展示
结合 Tooltip 组件,实现一个数值输入框,方便内容超长时的全量展现。
