my-crud is a vue table component modified based on D2-Crud. It contains a simple addition, deletion, and modification form, and adds some functions than the original version.
Use npm
npm i element-ui my-element-crud -S
Write the following content in main.js
:
import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import D2Crud from 'my-element-crud'
Vue . use ( ElementUI )
Vue . use ( D2Crud )
new Vue ( {
el : '#app' ,
render : h => h ( App )
} )
You can then use D2-Crud
in your project.
externals: D2Crud
https://cdn.d2.pub/packages/@d2-projects/[email protected]/d2-crud.js
custom: [
{
text : '更多' ,
type : 'text' ,
// size: 'small',
sort : 8 ,
emit : 'custom-edit' ,
show : ( index , row ) => true ,
more : [
{
text : '!!!!!' ,
emit : 'custom-pop' ,
show : ( index , row ) => true
}
]
}
]
mycom2 : {
title : "自带选择框" ,
value : "" ,
_sort : 4 ,
component : {
name : "el-select" ,
options : [
{ label : "测试1" , value : 1 } ,
{ label : "测试2" , value : 2 } ,
] ,
// 事件绑定
'@change' : ( e ) => {
console . log ( this . rowHandle ) ;
} ,
// 属性绑定
':size' : 'mini'
} ,
} ,
Solve the problem that the form-data-change event of the built-in selection box cannot be correctly passed to the parent component
Add custom view button
Add viewing function, elements are disabled by default when viewing
Custom component disabled needs to add disabled: Boolean in props. Write the component attribute: :disabled="disabled"
use:
< d2-crud v-bind : look-template = "addTemplate" > </ d2-crud >
rowHandle: {
look : {
text : "查看" ,
emit : "lookHandle"
} ,
}
Add custom button sorting function
use:
rowHandle: {
minWidth : "180px" ,
look : {
text : "查看" ,
emit : "lookHandle" ,
sort : 3
} ,
customs : [ {
text : '打卡记录' ,
emit : 'showRecord' ,
sort : 2
} ] ,
edit : {
text : "编辑" ,
emit : "editHandle" ,
type : "warning " ,
sort : 1
} ,
}
rowHandle: {
lookNoEle : {
text : "查看" ,
emit : "lookHandle"
} ,
}
mycom : {
title : "选择框" ,
value : "" ,
component : {
name : testCom ,
formatter ( val ) {
return val === 1 ? "测试1" : "测试2" ;
} ,
props : {
options : [
{ label : "测试1" , value : 1 } ,
{ label : "测试2" , value : 2 }
]
}
}
} ,
roleName : {
title : "角色名" ,
value : "" ,
class : "my_label" ,
component : {
placeholder : " 仅可输入英文大小写、数字"
}
} ,
-- Add dynamic display and hidden form form
roleName : {
title : "角色名" ,
value : "" ,
class : "my_label" ,
component : {
show : this . show === 1
placeholder : " 仅可输入英文大小写、数字"
}
} ,
Set the width of the form dialog: add-width="400px" :edit-width="400px"
=======
parent component
< d2-crud
@componentEvent:coma =" handle " >
</ d2-crud >
computed : {
addTemplate ( ) {
return {
coma : {
title : "自定义选择框a" ,
value : "" ,
component : {
name : coma ,
} ,
} ,
comb : {
title : "自定义选择框b" ,
value : "" ,
component : {
name : comb ,
} ,
} ,
}
} ,
method : {
handle ( data ) {
this . $refs . d2Crud . getRef ( "comb" ) . handleComponentEvent ( data ) ;
} }
Component A
<template>
<div>
<el-button @click="up">up123</el-button>
</div>
</template>
up() {
this.$emit("componentEvent", 123);
}
Component B
methods: {
handleComponentEvent ( data ) {
this . data = data
}
}