uni-td.vue 1.8 KB

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