demo4.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div>
  3. <p class="pb-10">自定义行样式:</p>
  4. <m-table :data="data1" border :rowClassName="tableRowClassName">
  5. <m-table-column prop="date" label="日期" />
  6. <m-table-column prop="name" label="姓名" />
  7. <m-table-column prop="address" label="地址" />
  8. </m-table>
  9. </div>
  10. <div class="mt-40">
  11. <p class="pb-10">自定义列样式:</p>
  12. <m-table :data="data1" border>
  13. <m-table-column prop="date" label="日期" />
  14. <m-table-column prop="name" label="姓名" className="table-error-column" />
  15. <m-table-column prop="address" label="地址" />
  16. </m-table>
  17. </div>
  18. <div class="mt-40">
  19. <p class="pb-10">自定义单元格样式:</p>
  20. <m-table :data="data3" border>
  21. <m-table-column prop="date" label="日期" />
  22. <m-table-column prop="name" label="姓名" />
  23. <m-table-column prop="address" label="地址" />
  24. </m-table>
  25. </div>
  26. </template>
  27. <script setup>
  28. const data1 = [
  29. {
  30. date: '2022-05-12',
  31. name: '后裔',
  32. address: '王者峡谷下塔旁'
  33. },
  34. {
  35. date: '2022-06-13',
  36. name: '鲁班',
  37. address: '在逛街'
  38. },
  39. {
  40. date: '2022-07-14',
  41. name: '孙尚香',
  42. address: '在打红buff'
  43. },
  44. {
  45. date: '2022-08-15',
  46. name: '狄仁杰',
  47. address: '在推塔'
  48. }
  49. ]
  50. const data3 = [
  51. {
  52. date: '2022-05-12',
  53. name: '后裔',
  54. address: '王者峡谷下塔旁'
  55. },
  56. {
  57. date: '2022-06-13',
  58. name: '鲁班',
  59. address: '在逛街',
  60. cellClassName: {
  61. date: 'table-info-cell-date',
  62. name: 'table-info-cell-name',
  63. address: 'table-info-cell-address'
  64. }
  65. },
  66. {
  67. date: '2022-07-14',
  68. name: '孙尚香',
  69. address: '在打红buff'
  70. },
  71. {
  72. date: '2022-08-15',
  73. name: '狄仁杰',
  74. address: '在推塔'
  75. },
  76. {
  77. date: '2022-08-15',
  78. name: '马可波罗',
  79. address: '在疯狂输出',
  80. cellClassName: {
  81. name: 'table-info-cell-name'
  82. }
  83. }
  84. ]
  85. const tableRowClassName = (row, index) => {
  86. if (index === 1) {
  87. return 'warning-row';
  88. } else if (index === 3) {
  89. return 'success-row';
  90. }
  91. return '';
  92. }
  93. </script>
  94. <style>
  95. .mt-40{
  96. margin-top: 40px;
  97. }
  98. .pb-10{
  99. padding-bottom: 10px;
  100. }
  101. .m-table .warning-row{
  102. background-color: #fdf5e6;
  103. }
  104. .m-table .success-row{
  105. background-color: #f0f9eb;
  106. }
  107. .m-table .table-error-column{
  108. background-color: #fef0f0;
  109. }
  110. .m-table .table-info-cell-date{
  111. background-color: pink;
  112. }
  113. .m-table .table-info-cell-name{
  114. background-color: skyblue;
  115. }
  116. .m-table .table-info-cell-address{
  117. background-color: burlywood;
  118. }
  119. </style>