0.1.1 • Published 4 years ago

@springleo/el-form-plus v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

el-form-plus npm.io

Install

yarn add @springleo/el-form-plus

Online Example

https://lq782655835.github.io/el-form-plus

Quick Start

Import modules and set up settings in main.js:

import ElFormPlus from '@springleo/el-form-plus'
Vue.use(ElFormPlus)

use <el-form-plus> in your page

<template>
    <el-form-plus
        :formModel="{
            name: '',
            age: '',
            address: '',
            sex: '男'
        }"
        :fieldList="[
            { label: '姓名', value: 'name', type: 'input' },
            { label: '年龄', value: 'age', type: 'input' },
            { label: '家庭住址', value: 'address', type: 'select', options: ['地址1', '地址2'].map(str => ({label: str, value: str})) },
            { label: '性别', value: 'sex', type: 'radio-group', options: ['男', '女'].map(str => ({label: str, value: str})) }
        ]"
    />
</template>

you can get preview by above code:

image

API

el-form-plus Props

基于el-form,所以Props支持el-form上所有props以及事件event。

PropTypeDefaultDescription
refObjObject返回form引用,如果手动validate需要用到
formModelObject{}el-form的model属性包装
fieldListArrayitem配置列表详细见如下
rulesObject{}el-form的rules,可定义所有form-item的规则,优先级最高
labelWidthstring100pxel-form的labelWidth
labelPositionstringleftel-form的labelPosition

fieldList Attrs

AttrTypeDefaultDescription
typeString必需。渲染的组件类型,支持input、textarea、select、radio-group、input-number、date、slot。同时支持动态组件,为约束完全的动态性,动态组件的命名请以el-dynamic-开头。
valueString必需。值字段,v-model绑定的值为this.datavalue
labelStringform-item标题
tooltipString标题附近的提示
disabledBooleanfalse是否禁用
placeholderString组件placeholder提示,默认input是‘请输入label’,select默认是‘请选择label’
requiredBooleanfalse校验规则:是否必须
patternRegex校验规则:满足正则
validatorfunction校验规则:自定义函数,最灵活
rulesArray\以上三种attr校验属于快速校验规则,使用rules可一次性定义form-item的规则
optionsArray针对select和radio-group组件,配置options list

由于type=slot用到v-slot作用域插槽,vue版本需要v2.6+

License

MIT