uni-th.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <view class="uni-table-th" :class="{'table--border':border}" :style="{width:width + 'px','text-align':align}">
  3. <slot></slot>
  4. </view>
  5. </template>
  6. <script>
  7. /**
  8. * Th 表头
  9. * @description 表格内的表头单元格组件
  10. * @tutorial https://ext.dcloud.net.cn/plugin?id=
  11. * @property {Number} width 单元格宽度
  12. * @property {Number} align = [left|center|right] 单元格对齐方式
  13. * @value left 单元格文字左侧对齐
  14. * @value center 单元格文字居中
  15. * @value right 单元格文字右侧对齐
  16. */
  17. export default {
  18. name: 'uniTh',
  19. options: {
  20. virtualHost: true
  21. },
  22. props: {
  23. width: {
  24. type: [String, Number],
  25. default: ''
  26. },
  27. align: {
  28. type: String,
  29. default: 'left'
  30. }
  31. },
  32. data() {
  33. return {
  34. border:false
  35. };
  36. },
  37. created() {
  38. this.root = this.getTable('uniTable')
  39. this.rootTr = this.getTable('uniTr')
  40. this.rootTr.minWidthUpdate(this.width?this.width:140)
  41. this.border = this.root.border
  42. },
  43. methods:{
  44. /**
  45. * 获取父元素实例
  46. */
  47. getTable(name) {
  48. let parent = this.$parent;
  49. let parentName = parent.$options.name;
  50. while (parentName !== name) {
  51. parent = parent.$parent;
  52. if (!parent) return false;
  53. parentName = parent.$options.name;
  54. }
  55. return parent;
  56. }
  57. }
  58. }
  59. </script>
  60. <style lang="scss">
  61. .uni-table-th {
  62. padding: 12px 10px;
  63. display: table-cell;
  64. // text-align: center;
  65. color: #333;
  66. font-weight: 500;
  67. border-bottom: 1px #ddd solid;
  68. font-size: 12px;
  69. // background-color: #efefef;
  70. box-sizing: border-box;
  71. }
  72. .table--border {
  73. border-right: 1px #ddd solid;
  74. }
  75. </style>