1.2.1 • Published 3 years ago

el-table-edit v1.2.1

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

一个基于 element-ui 的可编辑表格组件

使用 async-validator 验证

Install

  • 下载包 npm i el-table-edit
  • 全局注册
import ElTableEdit from "el-table-edit";
Vue.use(ElTableEdit);
  • 在浏览器中使用

    下载 dist 中的 js 和 css 文件并引入

Usage

<template>
  <ElTableEdit
    :data="tableData"
    :columns="columns"
    border
    stripe
    style="width: 100%"
    @submitRow="submit"
  >
    <template v-slot:column-actions="{ row, $index }">
      <el-button @click="delItem(row, $index)" type="danger" size="small">
        删除
      </el-button>
    </template>
  </ElTableEdit>
</template>
<script>
export default {
  data() {
    return {
      columns: [
        {
          title: "菜单名",
          key: "title",
          edit: true,
          rules: [
            { required: true, message: "请输入菜单名称" },
            {
              min: 2,
              max: 5,
              message: "长度在 2 到 5 个字符",
            },
          ],
          clearable: true,
        },
        {
          title: "路径",
          key: "path",
          edit: true,
          rules: [
            { required: true, message: "请输入菜单路径" },
            {
              pattern: /^\/[\w-/]*$/,
              message: "请输入正确的路径",
            },
          ],
          clearable: true,
        },
        {
          title: "图标",
          key: "icon",
          type: "icon",
          edit: true,
          rules: [],
          clearable: true,
        },
      ],
      tableData: [{ title: "首页", path: "/index", icon: "el-icon-s-home" }],
    };
  },
  methods: {
    submit(row, valid) {
      if (valid) {
        // 验证通过
      } else {
        // 验证不通过
      }
    },
  },
};
</script>

Api

ElTableEdit

参数说明类型可选值默认值
datatabledataArray[]
columns列配置Array[]
actionsWidth操作栏宽度Number250
editButText编辑按钮文字String编辑
submitButText保存按钮文字String保存
cancelButText取消按钮文字String取消
actionsFixed操作栏固定与 el-table 一致false
el-table 其他属性

columns

参数说明类型
title列标题
key与 data 对应的字段名String
width列宽度与 el-table 一致
minWidth列最小宽度与 el-table 一致
edit是否可编辑Boolean
rules可编辑时的验证规则Array
clearable编辑时的 input 是否可清空与 el-input 一致
type当前列字段的类型目前可选‘index’,‘selection’,‘icon’,‘select’ ,‘textarea’ ,默认‘text’
optionstype 为 select 时,用于过滤或选择的数组例: {label:"男",value:"1",},{label:"女",value:"2"}
fixed列固定与 el-table 一致

Events

事件名称说明回调参数
submitRow点击行保存时(row,valid)
el-table 其他事件

Slot

name说明props
header操作栏头部内容
append表格最后一行内容,与 el-tabel 一样
column-actions操作栏的内容,会在按钮之后,可用来做删除,打印等功能(row,\$index)
key自定义单元格的非编辑状态(row,\$index)