平安校园
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uni-td.vue 1.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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>