• 基础
    • 普通用法
    • 丰富表格
    • 合并菜单
    • 文本菜单
    • 图标菜单

    基础

    TIP

    1.0.0+

    普通用法

    基础 - 图1

    avue-table组件属性中,data数据的对象数组,option为表格要配置的数据列,v-model为当前编辑或者新增的表单对象,自动根据option中的column配置去加载对象注入进去

    1. <avue-crud :data="data" :option="option" v-model="obj" :before-close="beforeOpen"></avue-crud>
    2. </br>
    3. <el-tag>当前弹出框表单中的数据{}</el-tag>
    4. <script>
    5. export default {
    6. data() {
    7. return {
    8. obj:{},
    9. data: [
    10. {
    11. name:'张三',
    12. sex:'男',
    13. date:'1994-02-23 00:00:00'
    14. }, {
    15. name:'李四',
    16. sex:'女',
    17. date:'1994-02-23 00:00:00'
    18. }, {
    19. name:'王五',
    20. sex:'女',
    21. date:'1994-02-23 00:00:00'
    22. }, {
    23. name:'赵六',
    24. sex:'男',
    25. date:'1994-02-23 00:00:00'
    26. }
    27. ],
    28. option:{
    29. title:'表格的标题',
    30. page:false,
    31. align:'center',
    32. menuAlign:'center',
    33. column:[
    34. {
    35. label:'姓名',
    36. prop:'name'
    37. },
    38. {
    39. label:'性别',
    40. prop:'sex'
    41. },{
    42. label: "日期",
    43. prop: "date",
    44. type: "date",
    45. format: "yyyy-MM-dd hh:mm:ss",
    46. valueFormat: "yyyy-MM-dd hh:mm:ss",
    47. }
    48. ]
    49. }
    50. }
    51. }
    52. }
    53. </script>

    丰富表格

    该示例主要展示了表格丰富的显示效果。

    基础 - 图2

    1. <el-row style="margin-bottom:20px;font-size:15px">
    2. <el-col :span="4">显示边框: <el-switch size="small" v-model="showBorder"> </el-switch></el-col>
    3. <el-col :span="4">显示斑马纹: <el-switch size="small" v-model="showStripe"> </el-switch></el-col>
    4. <el-col :span="4">显示索引: <el-switch size="small" v-model="showIndex"> </el-switch></el-col>
    5. <el-col :span="4">显示多选框: <el-switch size="small" v-model="showCheckbox"> </el-switch></el-col>
    6. <el-col :span="4">显示表头: <el-switch size="small" v-model="showHeader"> </el-switch></el-col>
    7. <el-col :span="4">显示分页: <el-switch size="small" v-model="showPage"> </el-switch></el-col>
    8. </el-row>
    9. <el-row style="margin-bottom:20px">
    10. <el-radio-group v-model="sizeValue">
    11. <el-radio label="">默认</el-radio>
    12. <el-radio label="small">small</el-radio>
    13. <el-radio label="mini">mini</el-radio>
    14. </el-radio-group>
    15. </el-row>
    16. <avue-crud :data="data" :option="option0"></avue-crud>
    17. <script>
    18. export default {
    19. data() {
    20. return {
    21. obj:{},
    22. data: [
    23. {
    24. name:'张三',
    25. sex:'男'
    26. }, {
    27. name:'李四',
    28. sex:'女'
    29. }, {
    30. name:'王五',
    31. sex:'女'
    32. }, {
    33. name:'赵六',
    34. sex:'男'
    35. }
    36. ],
    37. showBorder: false,
    38. showStripe: false,
    39. showHeader: true,
    40. showIndex: true,
    41. showCheckbox: false,
    42. showPage:false,
    43. sizeValue:''
    44. }
    45. },
    46. computed: {
    47. option0(){
    48. return{
    49. title:'表格的标题',
    50. border:this.showBorder,
    51. stripe:this.showStripe,
    52. showHeader:this.showHeader,
    53. index:this.showIndex,
    54. size:this.sizeValue,
    55. selection:this.showCheckbox,
    56. page:this.showPage,
    57. align:'center',
    58. menuAlign:'center',
    59. column:[
    60. {
    61. label:'姓名',
    62. prop:'name'
    63. },
    64. {
    65. label:'性别',
    66. prop:'sex'
    67. }
    68. ]
    69. }
    70. }
    71. }
    72. }
    73. </script>

    合并菜单

    基础 - 图3

    配置menuTypemenu表格的操作栏目菜单合并,menuBtn卡槽为自定义卡槽,delBtneditBtn会消失,dateBtn控件的dateDefaulttrue时首次进来会加载回调方法,

    1. <avue-crud :data="data" :option="option1" v-model="obj" @date-change="dateChange">
    2. <template slot-scope="scope" slot="menuBtn">
    3. <el-dropdown-item divided @click.native="tip">自定义按钮</el-dropdown-item>
    4. </template>
    5. <template slot-scope="scope" slot="menu">
    6. <el-button size="small" @click.native="tip">自定义按钮</el-button>
    7. </template>
    8. </avue-crud>
    9. <script>
    10. export default {
    11. data() {
    12. return {
    13. obj:{},
    14. data: [
    15. {
    16. name:'张三',
    17. sex:'男',
    18. date:'1994-02-23 00:00:00'
    19. }, {
    20. name:'李四',
    21. sex:'女',
    22. date:'1994-02-23 00:00:00'
    23. }, {
    24. name:'王五',
    25. sex:'女',
    26. date:'1994-02-23 00:00:00'
    27. }, {
    28. name:'赵六',
    29. sex:'男',
    30. date:'1994-02-23 00:00:00'
    31. }
    32. ],
    33. option1:{
    34. title:'表格的标题',
    35. menuType:'menu',
    36. page:false,
    37. align:'center',
    38. dateBtn:true,
    39. dateDefault:true,
    40. menuAlign:'center',
    41. column:[
    42. {
    43. label:'姓名',
    44. prop:'name'
    45. },
    46. {
    47. label:'性别',
    48. prop:'sex'
    49. },{
    50. label: "日期",
    51. prop: "date",
    52. type: "date",
    53. format: "yyyy-MM-dd hh:mm:ss",
    54. valueFormat: "yyyy-MM-dd hh:mm:ss",
    55. }
    56. ]
    57. }
    58. }
    59. },
    60. methods: {
    61. dateChange(date){
    62. this.$message.success(date);
    63. },
    64. tip(){
    65. this.$message.success('自定义按钮');
    66. }
    67. }
    68. }
    69. </script>

    文本菜单

    基础 - 图4

    配置menuTypetext时表格操作栏为文本按钮

    1. <avue-crud :data="data" :option="option2" v-model="obj" @date-change="dateChange">
    2. <template slot-scope="scope" slot="menu">
    3. <el-button type="text" size="small" @click.native="tip">自定义按钮</el-button>
    4. </template>
    5. </avue-crud>
    6. <script>
    7. export default {
    8. data() {
    9. return {
    10. obj:{},
    11. data: [
    12. {
    13. name:'张三',
    14. sex:'男',
    15. date:'1994-02-23 00:00:00'
    16. }, {
    17. name:'李四',
    18. sex:'女',
    19. date:'1994-02-23 00:00:00'
    20. }, {
    21. name:'王五',
    22. sex:'女',
    23. date:'1994-02-23 00:00:00'
    24. }, {
    25. name:'赵六',
    26. sex:'男',
    27. date:'1994-02-23 00:00:00'
    28. }
    29. ],
    30. option2:{
    31. title:'表格的标题',
    32. menuType:'text',
    33. page:false,
    34. align:'center',
    35. dateBtn:true,
    36. dateDefault:true,
    37. menuAlign:'center',
    38. column:[
    39. {
    40. label:'姓名',
    41. prop:'name'
    42. },
    43. {
    44. label:'性别',
    45. prop:'sex'
    46. },{
    47. label: "日期",
    48. prop: "date",
    49. type: "date",
    50. format: "yyyy-MM-dd hh:mm:ss",
    51. valueFormat: "yyyy-MM-dd hh:mm:ss",
    52. }
    53. ]
    54. }
    55. }
    56. },
    57. methods: {
    58. dateChange(date){
    59. this.$message.success(date);
    60. },
    61. tip(){
    62. this.$message.success('自定义按钮');
    63. }
    64. }
    65. }
    66. </script>

    图标菜单

    基础 - 图5

    配置menuTypeicon时表格操作栏为图标按钮

    1. <avue-crud :data="data" :option="option3" v-model="obj" @date-change="dateChange">
    2. <template slot-scope="scope" slot="menu">
    3. <el-button size="small" @click.native="tip" icon="el-icon-share"></el-button>
    4. </template>
    5. </avue-crud>
    6. <script>
    7. export default {
    8. data() {
    9. return {
    10. obj:{},
    11. data: [
    12. {
    13. name:'张三',
    14. sex:'男',
    15. date:'1994-02-23 00:00:00'
    16. }, {
    17. name:'李四',
    18. sex:'女',
    19. date:'1994-02-23 00:00:00'
    20. }, {
    21. name:'王五',
    22. sex:'女',
    23. date:'1994-02-23 00:00:00'
    24. }, {
    25. name:'赵六',
    26. sex:'男',
    27. date:'1994-02-23 00:00:00'
    28. }
    29. ],
    30. option3:{
    31. title:'表格的标题',
    32. menuType:'icon',
    33. page:false,
    34. align:'center',
    35. dateBtn:true,
    36. dateDefault:true,
    37. menuAlign:'center',
    38. column:[
    39. {
    40. label:'姓名',
    41. prop:'name'
    42. },
    43. {
    44. label:'性别',
    45. prop:'sex'
    46. },{
    47. label: "日期",
    48. prop: "date",
    49. type: "date",
    50. format: "yyyy-MM-dd hh:mm:ss",
    51. valueFormat: "yyyy-MM-dd hh:mm:ss",
    52. }
    53. ]
    54. }
    55. }
    56. },
    57. methods: {
    58. dateChange(date){
    59. this.$message.success(date);
    60. },
    61. tip(){
    62. this.$message.success('自定义按钮');
    63. }
    64. }
    65. }
    66. </script>