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