u-th.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <view class="u-th" :style="[thStyle]">
  3. <slot></slot>
  4. </view>
  5. </template>
  6. <script>
  7. import { props } from './props';
  8. import { mpMixin } from '../../libs/mixin/mpMixin';
  9. import { mixin } from '../../libs/mixin/mixin';
  10. import { addUnit, $parent } from '../../libs/function/index';
  11. /**
  12. * Td 表格中的单元格
  13. * @description
  14. * @tutorial url
  15. * @property {String | Number}
  16. * @event {Function}
  17. * @example
  18. */
  19. export default {
  20. name: 'u-th',
  21. mixins: [mpMixin, mixin, props],
  22. props: {
  23. // 宽度,百分比或者具体带单位的值,如30%, 200rpx等,一般使用百分比
  24. width: {
  25. type: [String],
  26. default: ''
  27. }
  28. },
  29. data() {
  30. return {
  31. thStyle: {}
  32. }
  33. },
  34. created() {
  35. this.parent = false;
  36. },
  37. mounted() {
  38. this.parent = $parent.call(this, 'u-table');
  39. if (this.parent) {
  40. // 将父组件的相关参数,合并到本组件
  41. let style = {};
  42. if (this.width) style.flex = `0 0 ${this.width}`;
  43. style.textAlign = this.parent.align;
  44. style.padding = this.parent.padding;
  45. style.borderBottom = `solid 1px ${this.parent.borderColor}`;
  46. style.borderRight = `solid 1px ${this.parent.borderColor}`;
  47. Object.assign(style, this.parent.thStyle);
  48. this.thStyle = style;
  49. }
  50. }
  51. }
  52. </script>
  53. <style lang="scss" scoped>
  54. .u-th {
  55. @include flex;
  56. flex-direction: column;
  57. flex: 1;
  58. justify-content: center;
  59. font-size: 28rpx;
  60. color: $u-main-color;
  61. font-weight: bold;
  62. background-color: rgb(245, 246, 248);
  63. }
  64. </style>