1
1
<template >
2
- <view class =" nut-tabbar" :class =" { 'nut-tabbar-bottom': bottom, 'nut-tabbar-safebottom': safeAreaInsetBottom }" >
2
+ <div v-if =" bottom && placeholder" class =" nut-tabbar__placeholder" :style =" { height: height + 'px' }" >
3
+ <view
4
+ ref =" nutTabbar"
5
+ class =" nut-tabbar"
6
+ :class =" { 'nut-tabbar-bottom': bottom, 'nut-tabbar-safebottom': safeAreaInsetBottom }"
7
+ >
8
+ <slot ></slot >
9
+ </view >
10
+ </div >
11
+ <view
12
+ v-else
13
+ class =" nut-tabbar"
14
+ :class =" { 'nut-tabbar-bottom': bottom, 'nut-tabbar-safebottom': safeAreaInsetBottom }"
15
+ >
3
16
<slot ></slot >
4
17
</view >
5
18
</template >
6
19
7
20
<script lang="ts">
8
- import { provide , reactive , watch } from ' vue' ;
21
+ import { onMounted , provide , reactive , ref , toRefs , watch } from ' vue' ;
9
22
import { createComponent } from ' @/packages/utils/create' ;
23
+ import Taro from ' @tarojs/taro' ;
10
24
const { create } = createComponent (' tabbar' );
11
25
export default create ({
12
26
props: {
@@ -37,14 +51,20 @@ export default create({
37
51
safeAreaInsetBottom: {
38
52
type: Boolean ,
39
53
default: false
54
+ },
55
+ placeholder: {
56
+ type: Boolean ,
57
+ default: false
40
58
}
41
59
},
42
60
emits: [' tab-switch' , ' update:visible' ],
43
61
setup(props , { emit , slots }) {
62
+ const { bottom, placeholder } = toRefs (props );
44
63
const mdValue = reactive ({
45
64
val: props .visible ,
46
65
children: []
47
66
});
67
+ const height = ref ();
48
68
function changeIndex(index : number , active : number | string ) {
49
69
emit (' update:visible' , active );
50
70
parentData .modelValue = active ;
@@ -65,8 +85,20 @@ export default create({
65
85
parentData .modelValue = value ;
66
86
}
67
87
);
88
+ onMounted (() => {
89
+ if (bottom .value && placeholder .value ) {
90
+ setTimeout (() => {
91
+ const query = Taro .createSelectorQuery ();
92
+ query .select (' .nut-tabbar' ).boundingClientRect ();
93
+ query .exec ((res ) => {
94
+ height .value = res [0 ].height ;
95
+ });
96
+ }, 500 );
97
+ }
98
+ });
68
99
return {
69
- changeIndex
100
+ changeIndex ,
101
+ height
70
102
};
71
103
}
72
104
});
0 commit comments