custom-tabbar.vue
1.7 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<template>
<view>
<u-tabbar
:value="vuex_tabbar_index"
:fixed="true"
:safeAreaInsetBottom="true"
:placeholder="true"
:activeColor="vuex_active_color"
>
<u-tabbar-item
v-for="(tabbarItem, index) in vuex_tabbar"
:key="index"
:text="tabbarItem.text"
@click="switchTo()"
>
<image
class="image_class"
slot="active-icon"
:src="tabbarItem.selectedIconPath"
></image>
<image
class="image_class"
slot="inactive-icon"
:src="tabbarItem.iconPath"
></image>
</u-tabbar-item>
</u-tabbar>
</view>
</template>
<script>
import { mapState } from "vuex";
export default {
name: "custom-tabbar",
data() {
return {
tabbar: [], // tabbar信息
};
},
// 自定义组件中属性
props: ["activeColor"],
created() {
// 模拟调用服务端接口,显示首页和我的页面
// if (this.tabbarState == 1) {
// const storeTabbar = this.vuex_tabbar;
// this.tabbar = this.tabbar.concat(storeTabbar[0]).concat(storeTabbar[2]);
// }
// // 模拟调用服务端接口,显示首页、消息和我的页面
// if (this.tabbarState == 2) {
// this.tabbar = this.vuex_tabbar;
// }
// this.tabbar = this.vuex_tabbar;
},
methods: {
// 页面跳转
switchTo(event) {
const _this = this
wx.switchTab({
url: this.vuex_tabbar[event].pagePath,
success: () => {
this.$u.vuex('vuex_tabbar_index', event);
},
});
},
},
};
</script>
<style lang="scss">
.image_class {
width: 50rpx;
height: 50rpx;
}
</style>