/
table-td.vue
45 lines (44 loc) 路 1 KB
/
table-td.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<template>
<td :class="cls"><template v-if="prop || render">{{show}}</template><slot :data="data" :index="index"></slot></td>
</template>
<script>
import utils from '../../utils/utils';
export default {
name: 'hTableTd',
props: {
index: Number,
prop: String,
dict: String,
data: [Object, Array],
align: String,
unit: String,
render: Function,
className: String
},
data() {
return {};
},
computed: {
cls() {
return {
[`text-${this.align}`]: !!this.align,
[this.className]: !!this.className
};
},
show() {
if (this.prop == '$index') return this.index;
if (this.render) {
return this.render.call(null, this.data);
}
let value = this.data[this.prop];
if (this.dict) {
return utils.dictMapping(value, this.dict);
}
if (this.unit) {
return value === '' || value === null || value === undefined ? '' : `${value}${this.unit}`;
}
return value;
}
}
};
</script>