u-td.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <view class="u-td" :style="[tdStyle]">
  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-td',
  21. mixins: [mpMixin, mixin, props],
  22. props: {
  23. // 宽度,百分比或者具体带单位的值,如30%, 200rpx等,一般使用百分比
  24. width: {
  25. type: [String],
  26. default: 'auto'
  27. }
  28. },
  29. data() {
  30. return {
  31. tdStyle: {
  32. }
  33. }
  34. },
  35. created() {
  36. this.parent = false;
  37. },
  38. mounted() {
  39. this.parent = $parent.call(this, 'u-table');
  40. if (this.parent) {
  41. // 将父组件的相关参数,合并到本组件
  42. let style = {};
  43. if (this.width != "auto") style.flex = `0 0 ${this.width}`;
  44. style.textAlign = this.parent.align;
  45. style.fontSize = addUnit(this.parent.fontSize);
  46. style.padding = this.parent.padding;
  47. style.borderBottom = `solid 1px ${this.parent.borderColor}`;
  48. style.borderRight = `solid 1px ${this.parent.borderColor}`;
  49. style.color = this.parent.color;
  50. this.tdStyle = style;
  51. }
  52. }
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. @import "../../libs/css/components.scss";
  57. .u-td {
  58. @include flex;
  59. flex-direction: column;
  60. flex: 1;
  61. justify-content: center;
  62. font-size: 14px;
  63. color: $u-content-color;
  64. align-self: stretch;
  65. box-sizing: border-box;
  66. height: 100%;
  67. }
  68. </style>