Skip to content

输入框

输入框用于输入单行文本。

基础用法

ts
const config = {
  type: 'input',
  formItem: {
    label: '用户名'
  },
  input: {
    placeholder: '请输入用户名',
    maxLength: 20,
    allowClear: true
  }
}

API

属性说明类型默认值
addonAfter带标签的 input,设置后置标签stringslot
addonBefore带标签的 input,设置前置标签stringslot
allowClear可以点击清除图标删除内容booleanfalse
bordered是否有边框booleantrue
clearIcon自定义清除图标 (allowClear 为 true 时生效)slot
defaultValue输入框默认内容string-
disabled是否禁用状态,默认为 falsebooleanfalse
id输入框的 idstring-
maxlength最大长度number-
prefix带有前缀图标的 inputstring | slot-
showCount是否展示字数booleanfalse
status设置校验状态'error''warning'
size控件大小。注:标准表单内的输入框大小限制为 middle。可选 large middle smallstring-
suffix带有后缀图标的 inputstringslot
type声明 input 类型,同原生 input 标签的 type 属性,见:MDN(请直接使用 代替 type="textarea")。stringtext
value(v-model)输入框内容string-

更多属性请参考 Ant Design Vue Input

示例

vue
<script setup lang="ts">
const columns = [
  {
    title: '用户名',
    dataIndex: 'username',
    edit: {
      type: 'input',
      formItem: {
        required: true,
        rules: [
          { required: true, message: '请输入用户名' },
          { min: 3, max: 20, message: '长度在 3-20 个字符' }
        ]
      },
      input: {
        placeholder: '请输入用户名',
        maxLength: 20,
        allowClear: true
      }
    }
  },
  {
    title: '手机号',
    dataIndex: 'phone',
    edit: {
      type: 'input',
      formItem: {
        required: true
      },
      input: {
        placeholder: '请输入手机号',
        prefix: '+86',
        maxLength: 11
      }
    }
  }
]
</script>

根据 Apache-2.0 许可发布。