vue2 + element-ui,类似 antd procomponents 中的 Protable
npm install vue-ele-protable``javascript
// npm
npm i vue-ele-protable -D
//yarn
yarn add vue-ele-protable
`
`javascript
// 在 main.js中全局使用,或者可在单独文件中注入
import VueEleProtable from 'vue-ele-protable'
import "vue-ele-protable/vueProtable.css"
import Vue from 'vue'
Vue.use(VueEleProtable);
`简单案例:
`vue
:tableColumns="tableColumns"
:tableData="tableData"
:formProps="{ labelSuffix: ' :' }"
:paginationProps="{ total: 100 }"
:otherRenders="otherRenders"
:toolbar="toolbar"
v-model="proFormData"
@onSearch="onSearch"
:loading="loading"
/>
export default {
data() {
return {
loading: false,
proTableRef: {},
proFormData: {},
otherRenders: () => {
return (
tableColumns: [
{
type: "selection",
width: 55,
hideInSearch: true,
},
{
label: "id",
prop: "id",
placeholder: "请输入",
hideInTable: true
},
{
label: "姓名",
prop: "name",
placeholder: "请输入",
},
{
label: "性别",
prop: "gender",
render: ({ row }) => {
return row.gender === '1' ? '男' : row.gender === '2' ? '女' : '未知'
},
renderItem: () => {
return (
);
},
},
{
label: "操作",
prop: "option",
hideInSearch: true,
render: (record) => {
return (
onClick={() => {
console.log(record);
}}
>
编辑
);
},
},
],
tableData: [
{ name: "男男", gender: "1", id: "1" },
{ name: "女女", gender: "2", id: "2" },
{ name: "未知", gender: "0", id: "0" },
],
};
},
methods: {
onSearch(params) {
console.log(params);
},
},
};
``
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| --------- | ------------------------------------------------------------------------------------------- | ---------------------- | ---------------------- | ------ |
| label | 对应 el-table-column 的 label | string | - | - |
| type | 对应 el-table-column 的 type | string | selection/index/expand | - |
| prop | 对应 el-table-column 的 prop | string | - | - |
| render | 自定义渲染 table 中每一行值 | function (record) { return xxx } | - | - |
| renderItem | 自定义渲染 form 中每一项 | function () { return node } | - | - |
| width | 对应 el-table-column 的 width | string,number | - | - |
| hideInSearch | 是否在搜索栏中隐藏 | boolean | - | false |
| hideInTable | 是否在表格中隐藏 | boolean | - | false |
| align | 对应 el-table-column 的 align | string | left/center/right | left |
| fixed | 对应 el-table-column 的 fixed | string, boolean | true, left, right | - |