uni-td.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <!-- #ifdef H5 -->
  3. <td class="uni-table-td" :rowspan="rowspan" :colspan="colspan" :class="{'table--border':border}" :style="{width:width + 'px','text-align':align}">
  4. <slot></slot>
  5. </td>
  6. <!-- #endif -->
  7. <!-- #ifndef H5 -->
  8. <!-- :class="{'table--border':border}" -->
  9. <view class="uni-table-td" :class="{'table--border':border}" :style="{width:width + 'px','text-align':align}">
  10. <slot></slot>
  11. </view>
  12. <!-- #endif -->
  13. </template>
  14. <script>
  15. /**
  16. * Td 单元格
  17. * @description 表格中的标准单元格组件
  18. * @tutorial https://ext.dcloud.net.cn/plugin?id=3270
  19. * @property {Number} align = [left|center|right] 单元格对齐方式
  20. */
  21. export default {
  22. name: 'uniTd',
  23. options: {
  24. // #ifdef MP-TOUTIAO
  25. virtualHost: false,
  26. // #endif
  27. // #ifndef MP-TOUTIAO
  28. virtualHost: true
  29. // #endif
  30. },
  31. props: {
  32. width: {
  33. type: [String, Number],
  34. default: ''
  35. },
  36. align: {
  37. type: String,
  38. default: 'left'
  39. },
  40. rowspan: {
  41. type: [Number,String],
  42. default: 1
  43. },
  44. colspan: {
  45. type: [Number,String],
  46. default: 1
  47. }
  48. },
  49. data() {
  50. return {
  51. border: false
  52. };
  53. },
  54. created() {
  55. this.root = this.getTable()
  56. this.border = this.root.border
  57. },
  58. methods: {
  59. /**
  60. * 获取父元素实例
  61. */
  62. getTable() {
  63. let parent = this.$parent;
  64. let parentName = parent.$options.name;
  65. while (parentName !== 'uniTable') {
  66. parent = parent.$parent;
  67. if (!parent) return false;
  68. parentName = parent.$options.name;
  69. }
  70. return parent;
  71. },
  72. }
  73. }
  74. </script>
  75. <style lang="scss">
  76. $border-color:#EBEEF5;
  77. .uni-table-td {
  78. display: table-cell;
  79. padding: 8px 10px;
  80. font-size: 14px;
  81. border-bottom: 1px $border-color solid;
  82. font-weight: 400;
  83. color: #606266;
  84. line-height: 23px;
  85. box-sizing: border-box;
  86. }
  87. .table--border {
  88. border-right: 1px $border-color solid;
  89. }
  90. </style>