uni-td.vue 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. virtualHost: true
  25. },
  26. props: {
  27. width: {
  28. type: [String, Number],
  29. default: ''
  30. },
  31. align: {
  32. type: String,
  33. default: 'left'
  34. },
  35. rowspan: {
  36. type: [Number,String],
  37. default: 1
  38. },
  39. colspan: {
  40. type: [Number,String],
  41. default: 1
  42. }
  43. },
  44. data() {
  45. return {
  46. border: false
  47. };
  48. },
  49. created() {
  50. this.root = this.getTable()
  51. this.border = this.root.border
  52. },
  53. methods: {
  54. /**
  55. * 获取父元素实例
  56. */
  57. getTable() {
  58. let parent = this.$parent;
  59. let parentName = parent.$options.name;
  60. while (parentName !== 'uniTable') {
  61. parent = parent.$parent;
  62. if (!parent) return false;
  63. parentName = parent.$options.name;
  64. }
  65. return parent;
  66. },
  67. }
  68. }
  69. </script>
  70. <style lang="scss">
  71. $border-color:#EBEEF5;
  72. .uni-table-td {
  73. display: table-cell;
  74. padding: 8px 10px;
  75. font-size: 14px;
  76. border-bottom: 1px $border-color solid;
  77. font-weight: 400;
  78. color: #606266;
  79. line-height: 23px;
  80. box-sizing: border-box;
  81. }
  82. .table--border {
  83. border-right: 1px $border-color solid;
  84. }
  85. </style>