1.2.8 • Published 3 years ago

element-form-plugin v1.2.8

Weekly downloads
12
License
ISC
Repository
github
Last release
3 years ago

表单插件

基于Element,根据配置为网页添加表单

Features

  • 配置Element里的DateTimePicker、Select、Input、Cascader等表单项
  • 配置多余的表单项,默认收起,可展开
  • 支持“查询”和“重置”
  • 给表单项配置默认值
  • 动态地显示或隐藏表单项

引入

// main.js

import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import elementForm from 'element-form-plugin'
import App from './App.vue'

Vue.use(ElementUI)
Vue.use(elementForm)

new Vue({
  render: h => h(App),
}).$mount('#app')

// index.vue

<element-form :initItems="items">
  <template #Buttons>
    <el-button type="primary" @click="save">保存</el-button>
  </template>
</element-form>
<!-- <element-form :initItems="items" :initPosition="position" :inline="true" /> -->
<!-- <element-form :initItems="items" /> -->

<script>
export default {
  data () {
    return {
      items: [], // 详见props
      position: 2 // 详见props
    }
  }
}
</script>

props

items

  • 类型:Array<object>

  • 默认值:[]

  • 元素的属性的列表:

参数说明类型required默认值
tagElement里的表单项的英文名stringtrue-
value绑定值stringtrue-
label表单项的标签stringfalse-
optionsSelect或Cascader的选项的列表,详见optionsArray<object>false-
isHidden被用于v-if,控制表单项是否渲染booleanfalsefalse
defaultValue表单项的默认值anyfalse-
change表单项的值变化时触发functionfalse-
prepend复合型输入框,指定前置的内容,详见prependobjectfalse-
props级联,配置选项,与Element中的一致objectfalse-
  • options

与Element中的一致,支持异步传入,例:

options: [
  {
    value: 'apple',
    label: '苹果'
  }, 
  {
    value: 'banana',
    label: '香蕉'
  }
]
  • prepend

position

  • 指定按钮组(查询、重置、更多条件)插入到表单项列表中的索引值

  • 类型:number

  • 默认把按钮组插入到表单项列表的末尾

inline

  • 行内表单模式,与Element中的一致

  • 类型:boolean

Events

事件名说明参数参数类型
search点击“查询”或“重置”按钮时触发已渲染的所有表单项的值object

例:

// items
[
  {
    tag: 'Select',
    value: 'region',
    label: '活动区域',
    options: [
      {
        value: 'beijing',
        label: '区域一'
      }, 
      {
        value: 'shanghai',
        label: '区域二'
      }
    ]
  }
]

// search事件的参数
{
  region: 'beijing'
}

Methods

方法名说明
getFields返回表单内各字段的值
resetFields重置表单

slot

name说明
Buttons插入至表单内的按钮,默认为“查询”和“重置”
1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago