|
1 | 1 | <template> |
2 | | - <view class="uni-padding-wrap"> |
3 | | - <page-head :title="title"></page-head> |
4 | | - <button @click="setTabBarBadge"> |
5 | | - {{ !hasSetTabBarBadge ? '设置tab徽标' : '移除tab徽标' }} |
6 | | - </button> |
7 | | - <button @click="showTabBarRedDot"> |
8 | | - {{ !hasShownTabBarRedDot ? '显示红点' : '移除红点'}} |
9 | | - </button> |
10 | | - <button @click="customStyle"> |
11 | | - {{ !hasCustomedStyle ? '自定义Tab样式' : '移除自定义样式'}} |
12 | | - </button> |
13 | | - <button @click="customItem"> |
14 | | - {{ !hasCustomedItem ? '自定义Tab信息' : '移除自定义信息' }} |
15 | | - </button> |
16 | | - <button @click="hideTabBar"> |
17 | | - {{ !hasHiddenTabBar ? '隐藏TabBar' : '显示TabBar' }} |
18 | | - </button> |
19 | | - <view class="btn-area"> |
20 | | - <button type="primary" @click="navigateBack">返回上一级</button> |
21 | | - </view> |
22 | | - </view> |
| 2 | + <view class="uni-padding-wrap"> |
| 3 | + <page-head :title="title"></page-head> |
| 4 | + <button @click="setTabBarBadge"> |
| 5 | + {{ !hasSetTabBarBadge ? '设置tab徽标' : '移除tab徽标' }} |
| 6 | + </button> |
| 7 | + <button @click="showTabBarRedDot"> |
| 8 | + {{ !hasShownTabBarRedDot ? '显示红点' : '移除红点'}} |
| 9 | + </button> |
| 10 | + <button @click="customStyle"> |
| 11 | + {{ !hasCustomedStyle ? '自定义Tab样式' : '移除自定义样式'}} |
| 12 | + </button> |
| 13 | + <button @click="customItem"> |
| 14 | + {{ !hasCustomedItem ? '自定义Tab信息' : '移除自定义信息' }} |
| 15 | + </button> |
| 16 | + <button @click="hideTabBar"> |
| 17 | + {{ !hasHiddenTabBar ? '隐藏TabBar' : '显示TabBar' }} |
| 18 | + </button> |
| 19 | + <view class="btn-area"> |
| 20 | + <button type="primary" @click="navigateBack">返回上一级</button> |
| 21 | + </view> |
| 22 | + </view> |
23 | 23 | </template> |
24 | 24 |
|
25 | 25 | <script> |
26 | | - export default { |
27 | | - data() { |
28 | | - return { |
29 | | - title: 'tababr', |
30 | | - hasSetTabBarBadge: false, |
31 | | - hasShownTabBarRedDot: false, |
32 | | - hasCustomedStyle: false, |
33 | | - hasCustomedItem: false, |
34 | | - hasHiddenTabBar: false |
35 | | - } |
36 | | - }, |
37 | | - methods: { |
38 | | - navigateBack() { |
39 | | - this.$emit('unmount') |
40 | | - }, |
41 | | - setTabBarBadge() { |
42 | | - if (!this.hasSetTabBarBadge) { |
43 | | - uni.setTabBarBadge({ |
44 | | - index: 1, |
45 | | - text: '1' |
46 | | - }) |
47 | | - }else{ |
48 | | - uni.removeTabBarBadge({ |
49 | | - index: 1 |
50 | | - }) |
51 | | - } |
52 | | - this.hasSetTabBarBadge = !this.hasSetTabBarBadge |
53 | | - }, |
54 | | - showTabBarRedDot() { |
55 | | - if (!this.hasShownTabBarRedDot) { |
56 | | - uni.showTabBarRedDot({ |
57 | | - index: 1 |
58 | | - }) |
59 | | - }else{ |
60 | | - uni.hideTabBarRedDot({ |
61 | | - index: 1 |
62 | | - }) |
63 | | - } |
64 | | - this.hasShownTabBarRedDot = !this.hasShownTabBarRedDot |
65 | | - }, |
66 | | - hideTabBar() { |
67 | | - if(!this.hasHiddenTabBar){ |
68 | | - uni.hideTabBar() |
69 | | - }else{ |
70 | | - uni.showTabBar() |
71 | | - } |
72 | | - this.hasHiddenTabBar = !this.hasHiddenTabBar |
73 | | - }, |
74 | | - customStyle() { |
75 | | - if (this.hasCustomedStyle) { |
76 | | - uni.setTabBarStyle({ |
77 | | - color: '#7A7E83', |
78 | | - selectedColor: '#007AFF', |
79 | | - backgroundColor: '#F8F8F8', |
80 | | - borderStyle:'black' |
81 | | - }) |
82 | | - }else{ |
83 | | - uni.setTabBarStyle({ |
84 | | - color: '#FFF', |
85 | | - selectedColor: '#007AFF', |
86 | | - backgroundColor: '#000000', |
87 | | - borderStyle:'black' |
88 | | - }) |
89 | | - } |
90 | | - this.hasCustomedStyle = !this.hasCustomedStyle |
91 | | - }, |
92 | | - customItem() { |
93 | | - let tabBarOptions = { |
94 | | - index: 1, |
95 | | - text: '接口', |
96 | | - iconPath: '/static/api.png', |
97 | | - selectedIconPath: '/static/apiHL.png' |
98 | | - } |
99 | | - if (this.hasCustomedItem) { |
100 | | - uni.setTabBarItem(tabBarOptions) |
101 | | - } else { |
102 | | - tabBarOptions.text = 'API' |
103 | | - uni.setTabBarItem(tabBarOptions) |
104 | | - } |
105 | | - this.hasCustomedItem = !this.hasCustomedItem |
106 | | - } |
107 | | - } |
108 | | - } |
| 26 | + export default { |
| 27 | + data() { |
| 28 | + return { |
| 29 | + title: 'tababr', |
| 30 | + hasSetTabBarBadge: false, |
| 31 | + hasShownTabBarRedDot: false, |
| 32 | + hasCustomedStyle: false, |
| 33 | + hasCustomedItem: false, |
| 34 | + hasHiddenTabBar: false |
| 35 | + } |
| 36 | + }, |
| 37 | + destroyed() { |
| 38 | + if (this.hasSetTabBarBadge) { |
| 39 | + uni.removeTabBarBadge({ |
| 40 | + index: 1 |
| 41 | + }) |
| 42 | + } |
| 43 | + if (this.hasShownTabBarRedDot) { |
| 44 | + uni.hideTabBarRedDot({ |
| 45 | + index: 1 |
| 46 | + }) |
| 47 | + } |
| 48 | + if (this.hasHiddenTabBar) { |
| 49 | + uni.showTabBar() |
| 50 | + } |
| 51 | + if (this.hasCustomedStyle) { |
| 52 | + uni.setTabBarStyle({ |
| 53 | + color: '#7A7E83', |
| 54 | + selectedColor: '#007AFF', |
| 55 | + backgroundColor: '#F8F8F8', |
| 56 | + borderStyle: 'black' |
| 57 | + }) |
| 58 | + } |
| 59 | +
|
| 60 | + if (this.hasCustomedItem) { |
| 61 | + let tabBarOptions = { |
| 62 | + index: 1, |
| 63 | + text: '接口', |
| 64 | + iconPath: '/static/api.png', |
| 65 | + selectedIconPath: '/static/apiHL.png' |
| 66 | + } |
| 67 | + uni.setTabBarItem(tabBarOptions) |
| 68 | + } |
| 69 | + }, |
| 70 | + methods: { |
| 71 | + navigateBack() { |
| 72 | + this.$emit('unmount') |
| 73 | + }, |
| 74 | + setTabBarBadge() { |
| 75 | + if (!this.hasSetTabBarBadge) { |
| 76 | + uni.setTabBarBadge({ |
| 77 | + index: 1, |
| 78 | + text: '1' |
| 79 | + }) |
| 80 | + } else { |
| 81 | + uni.removeTabBarBadge({ |
| 82 | + index: 1 |
| 83 | + }) |
| 84 | + } |
| 85 | + this.hasSetTabBarBadge = !this.hasSetTabBarBadge |
| 86 | + }, |
| 87 | + showTabBarRedDot() { |
| 88 | + if (!this.hasShownTabBarRedDot) { |
| 89 | + uni.showTabBarRedDot({ |
| 90 | + index: 1 |
| 91 | + }) |
| 92 | + } else { |
| 93 | + uni.hideTabBarRedDot({ |
| 94 | + index: 1 |
| 95 | + }) |
| 96 | + } |
| 97 | + this.hasShownTabBarRedDot = !this.hasShownTabBarRedDot |
| 98 | + }, |
| 99 | + hideTabBar() { |
| 100 | + if (!this.hasHiddenTabBar) { |
| 101 | + uni.hideTabBar() |
| 102 | + } else { |
| 103 | + uni.showTabBar() |
| 104 | + } |
| 105 | + this.hasHiddenTabBar = !this.hasHiddenTabBar |
| 106 | + }, |
| 107 | + customStyle() { |
| 108 | + if (this.hasCustomedStyle) { |
| 109 | + uni.setTabBarStyle({ |
| 110 | + color: '#7A7E83', |
| 111 | + selectedColor: '#007AFF', |
| 112 | + backgroundColor: '#F8F8F8', |
| 113 | + borderStyle: 'black' |
| 114 | + }) |
| 115 | + } else { |
| 116 | + uni.setTabBarStyle({ |
| 117 | + color: '#FFF', |
| 118 | + selectedColor: '#007AFF', |
| 119 | + backgroundColor: '#000000', |
| 120 | + borderStyle: 'black' |
| 121 | + }) |
| 122 | + } |
| 123 | + this.hasCustomedStyle = !this.hasCustomedStyle |
| 124 | + }, |
| 125 | + customItem() { |
| 126 | + let tabBarOptions = { |
| 127 | + index: 1, |
| 128 | + text: '接口', |
| 129 | + iconPath: '/static/api.png', |
| 130 | + selectedIconPath: '/static/apiHL.png' |
| 131 | + } |
| 132 | + if (this.hasCustomedItem) { |
| 133 | + uni.setTabBarItem(tabBarOptions) |
| 134 | + } else { |
| 135 | + tabBarOptions.text = 'API' |
| 136 | + uni.setTabBarItem(tabBarOptions) |
| 137 | + } |
| 138 | + this.hasCustomedItem = !this.hasCustomedItem |
| 139 | + } |
| 140 | + } |
| 141 | + } |
109 | 142 | </script> |
110 | 143 |
|
111 | 144 | <style> |
112 | | - button { |
113 | | - margin-top: 30upx; |
114 | | - } |
| 145 | + button { |
| 146 | + margin-top: 30upx; |
| 147 | + } |
115 | 148 |
|
116 | | - .btn-area { |
117 | | - padding-top: 30upx; |
118 | | - } |
| 149 | + .btn-area { |
| 150 | + padding-top: 30upx; |
| 151 | + } |
119 | 152 | </style> |
0 commit comments