npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

el-render-form

v1.0.0

Published

a vue component with element-ui form.

Downloads

8

Readme

el-render-form

环境

vue2.5+

element-ui 2.0+

安装

npm安装

npm i el-render-form -S

引入el-render-form

import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import ElRenderForm from 'el-render-form'
import App from './App.vue'

Vue.use(ElementUI)
Vue.use(ElRenderForm)

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

示例

<template>
<el-render-form
  :edit="true"
  :data="formData"
  :fileds="fields"
  :orders="orders"
  :inline="true"
  :model="formData"
  :rules="rules"
  ref="ruleForm"
  label-width="150px"
  class="edit-form">
</el-render-form>
</template>

tip: 在el-form原有基础上加了edit,data,fileds,orders这几个props,el-form原有的不变

基本使用

export default {
  data () {
    return {
      formData: {
        name: '',
        sex: 0,
        birthday: '2018-01-01'
      },
      rules: {
        name: { required: true, message: '姓名为必填', trigger: 'blur' }
      },
      fields: {
        name: {
          label: '姓名',
          type: 'input',
          props: {
            type: 'text',
            size: 'small',
            placeholder: '请输入姓名'
          }
        },
        sex: {
          label: '性别',
          type: 'select',
          options: [
            { value: 0, label: '男' },
            { value: 1, label: '女' }
          ],
          optionKey: {
            type: Number
          }
        },
        birthday: {
          label: '生日',
          type: 'date-picker',
          props: {
            'value-format': 'yyyy-MM-dd'
          }
        }
      },
      orders: ['name', 'sex', 'birthday']
    }
  }
}

tip: 以下只展示配置项修改内容

自定义非编辑状态的显示内容

fields: {
  name: {
    label: '姓名',
    type: 'input',
    render (h, { data, value, i }) {
      return h(
        'span',
        `${value}(昵称)`
      )
    }
  }
}

tip: 不清楚render函数的写法?vue 渲染函数&jsx

使用jsx

fields: {
  sex: {
    label: '性别',
    type: 'select',
    options: [
      { sex: 0, sexName: '男' },
      { sex: 1, sexName: '女' }
    ],
    optionKey: {
      value: 'sex',
      label: 'sexName',
      type: Number
    }
  }
}

tip: 这里的type: Number指option中value的类型

自定义select中option的key

fields: {
  name: {
    label: '姓名',
    type: 'input',
    render (h, { data, value, i }) {
      return (<span>{`${value}(昵称)`}</span>)
    }
  }
}

使用slot自定义

<el-render-form>
  <span slot="sex" slot-scope="{ edit, data, value, i }">
    {{ `现在是${edit ? '编辑' : '浏览'}状态,当前值是${value}` }}
  </span>
</el-render-form>
fields: {
  sex: {
    label: '性别',
    slot: 'sex'
  }
}

当前问题

  1. 初始化数据data必须定义各个字段的默认值
// 错误
formData: {}
// 正确
formData: {
  name: '',
  sex: 0,
  birthday: ''
}
  1. slot编辑状态与非编辑状态无法分开配置

Form Attributes

| 参数 | 说明 | 类型 | 可选值 | 默认值 | |-----|-----|------|-------|-------| | data | 表单数据绑定对象 | object | - | - | | fileds | 表单各项配置对象(key要对应data上各项的key) | object | - | - | | orders | 表单各项排序 | array | - | 按照fileds顺序排序 |

fileds 配置项

| 参数 | 说明 | 类型 | 可选值 | 默认值 | |-----|-----|------|-------|-------| | label | 表单的label显示内容 | string | - | - | | type | 编辑状态下表单类型 | string | input/select/date-picker | input | | props | 绑定在表单组件(input/select/date-picker)上的props | object | - | - | | render | 非编辑状态下显示的内容 | function | - | function(h: renderFunction, option: { data: 表单数据对象, value: 当前项的值, i: 当前项的key }) | options | type为select时的选择项 | array/object | [{ value: any, label: string }, ...]/{ [value]: label, ... } | - | | optionKey | options选项的value与label自定义key与类型 | object | { type: Number | String } | { value: 'value', label: 'label', type: String } |