Vant IndexBar 索引栏 写左右联动

9 篇文章 0 订阅
1 篇文章 0 订阅

<template>

<van-index-bar  :sticky="true" :sticky-offset-top="1" :index-list="indexList" class="anchor" sticky>

            <div v-for="(item,index) in cate" :key="index">

<!-- //这里的indexList[index]要和{{indexList[index]}} 一样才能触发点击事件-->
                <van-index-anchor class="index" :index="indexList[index]">{{indexList[index]}}</van-index-anchor>
                <div class="mar d-flex flex-wrap">
                    <div class="fon" v-for="(item1,index1) in item" :key="index1">
                        <van-image class="img " :src="item1.cover" />
                        <div class="name ">{{item1.name}}</div>
                    </div>
                </div>

            </div>
        </van-index-bar>

</template>    

<script>

import Slots from '@/components/Slots.vue'
    export default {
        name: 'Cart',
        data() {
            return {
                indexList: [

                ],
                cate: [

                ],

            }
        },
        components: {
            Slots
        },
        methods: {

   //获取数据   
            getData() {
                this.$axios('/api/category/app_category').then(v => {
                    console.log(v.data.data);

                    v.data.data.forEach(res => {
                        this.indexList.push(res.name)
                        // console.log(res.app_category_items);
                        // this.cate.push(res.app_category_items)
                        this.cate.push(res.app_category_items)
                        // console.log(this.cate);

                    })


                })
            },


        },
        mounted() {
            // console.log(this.getData());
            this.getData()

        },


    }
</script>

下面的样式会使用到 样式穿透  :: v-deep 

<style scoped>
    ::v-deep .van-index-bar__sidebar {
        /* left: 0rem; */
        position: fixed;
        left: 0rem;
        top: 0rem;
        margin-top: 7.285714rem;
        width: 25%;
    }

    .index {
        text-align: center;
        width: 75%;
        float: right;
    }

    ::v-deep .van-index-bar__index,
    .van-index-bar__index--active {
        background-color: white;
        margin-bottom: 1.685714rem;
    }

    .fon {
        font-size: 0.428571rem;
        /* margin-left: 0.942857rem; */
        margin: 0.142857rem 0.071428rem 0 0.071428rem;
    }

    .mar {
        width: 75%;
        float: right;
    }

    .name {
        text-align: center;
        margin: auto;
    }

    .img {
        width: 2.128571rem;
        height: 2.828571rem;
    }

</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值