uni-td.vue 1.4 KB

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