u-td.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <view :style="[tdStyle]" class="u-td">
  3. <slot></slot>
  4. </view>
  5. </template>
  6. <script>
  7. /**
  8. * td td单元格
  9. * @description 表格组件一般用于展示大量结构化数据的场景(搭配u-table使用)
  10. * @tutorial https://www.uviewui.com/components/table.html#td-props
  11. * @property {String Number} width 单元格宽度百分比或者具体带单位的值,如30%, 200rpx等,一般使用百分比,单元格宽度默认为均分tr的长度(默认auto)
  12. * @example <u-td>二年级</u-td>
  13. */
  14. export default {
  15. name: "u-td",
  16. props: {
  17. // 宽度,百分比或者具体带单位的值,如30%, 200rpx等,一般使用百分比
  18. width: {
  19. type: [Number, String],
  20. default: 'auto'
  21. }
  22. },
  23. data() {
  24. return {
  25. tdStyle: {}
  26. }
  27. },
  28. created() {
  29. this.parent = false;
  30. },
  31. mounted() {
  32. this.parent = this.$u.$parent.call(this, 'u-table');
  33. if (this.parent) {
  34. // 将父组件的相关参数,合并到本组件
  35. let style = {};
  36. if (this.width != "auto") style.flex = `0 0 ${this.width}`;
  37. style.textAlign = this.parent.align;
  38. style.fontSize = this.parent.fontSize + 'rpx';
  39. style.padding = this.parent.padding;
  40. style.borderBottom = `solid 1px ${this.parent.borderColor}`;
  41. style.borderRight = `solid 1px ${this.parent.borderColor}`;
  42. style.color = this.parent.color;
  43. this.tdStyle = style;
  44. }
  45. }
  46. };
  47. </script>
  48. <style lang="scss" scoped>
  49. @import "../../libs/css/style.components.scss";
  50. .u-td {
  51. @include vue-flex;
  52. flex-direction: column;
  53. flex: 1;
  54. justify-content: center;
  55. font-size: 28 rpx;
  56. color: $u-content-color;
  57. align-self: stretch;
  58. box-sizing: border-box;
  59. height: 100%;
  60. }
  61. </style>