Lou
2024-03-19 d34c7c19ab062b8e99b7af7e1d44e009c1b9b739
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
<template>
    <view>
        <u-tabbar class="custom-tabbar" zIndex="9999" :value="current" :fixed="true" :active-color="activeColor"
            :inactive-color="inactiveColor">
            <u-tabbar-item :text="item.name" @click="changeTabbar(item.url,index,item.name)"
                v-for="(item,index) in tabbarList" :key="index">
                <image class="tabbar-icon" slot="active-icon" :src="item.iconPathSelected"></image>
                <image class="tabbar-icon" slot="inactive-icon" :src="item.iconPath"></image>
            </u-tabbar-item>
        </u-tabbar>
    </view>
</template>
 
<script>
    export default {
        props: {
            current: Number,
            list: {
                type: Array,
                default: () => []
            }
        },
        data() {
            return {
                tabbarList: [],
                inactiveColor: '#AFB8C3',
                activeColor: '#5086FA',
            }
        },
        watch: {
            list: {
                handler(newVal) {
                    if (newVal && newVal.length > 0) {
                        this.tabbarList = newVal
                    }
                },
                deep: true,
                immediate: true
            }
        },
 
        methods: {
            changeTabbar(url, index) {
                if (this.current == index) return
                uni.switchTab({
                    url
                })
                this.$emit("change", name)
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .tabbar-icon {
        width: 56rpx;
        height: 56rpx;
    }
</style>