Sanakey
2021-01-31 53cc6f817625897935fb10c3845ad7be400f3036
提交 | 用户 | age
d98d05 1 import { VantComponent } from '../common/component';
53cc6f 2 import { useChildren } from '../common/relation';
S 3 import { getRect } from '../common/utils';
d98d05 4 VantComponent({
53cc6f 5   relation: useChildren('tabbar-item', function () {
S 6     this.updateChildren();
7   }),
d98d05 8   props: {
S 9     active: {
10       type: null,
11       observer: 'updateChildren',
12     },
13     activeColor: {
14       type: String,
15       observer: 'updateChildren',
16     },
17     inactiveColor: {
18       type: String,
19       observer: 'updateChildren',
20     },
21     fixed: {
22       type: Boolean,
23       value: true,
53cc6f 24       observer: 'setHeight',
S 25     },
26     placeholder: {
27       type: Boolean,
28       observer: 'setHeight',
d98d05 29     },
S 30     border: {
31       type: Boolean,
32       value: true,
33     },
34     zIndex: {
35       type: Number,
36       value: 1,
37     },
38     safeAreaInsetBottom: {
39       type: Boolean,
40       value: true,
41     },
42   },
53cc6f 43   data: {
S 44     height: 50,
45   },
d98d05 46   methods: {
S 47     updateChildren() {
48       const { children } = this;
49       if (!Array.isArray(children) || !children.length) {
53cc6f 50         return;
d98d05 51       }
53cc6f 52       children.forEach((child) => child.updateFromParent());
d98d05 53     },
53cc6f 54     setHeight() {
S 55       if (!this.data.fixed || !this.data.placeholder) {
56         return;
d98d05 57       }
53cc6f 58       wx.nextTick(() => {
S 59         getRect(this, '.van-tabbar').then((res) => {
60           this.setData({ height: res.height });
61         });
62       });
d98d05 63     },
S 64   },
65 });