顶部滑动导航菜单栏

1162622-20190904153723411-86375177.png

参考:https://ext.dcloud.net.cn/plugin?id=738

  • template使用

<template>
    <view class="slidingMenu">
        <haverster-slidingMenu :list="list" :color="color" @changes="getIndex"></haverster-slidingMenu>
        <view class="contentList">
            <image :src="imageList[activeIndex]" mode=""></image>
        </view>
    </view>
</template>

  • JS
<script>
    import haversterSlidingMenu from '@/components/haverster-slidingMenu/haversterSlidingMenu.vue';
    export default {
        components: { haversterSlidingMenu },
        data() {
            return {
                list: ['男装', '母婴', '数码', '箱包', '生鲜', '食品', '饰品', '女装'], //默认传到顶部菜单栏的数据
                activeIndex: '0', ///菜单栏选中状态的index值
                color: 'white', //设置菜单的背景颜色
                imageList: [
                    'http://pic1.win4000.com/mobile/2018-09-04/5b8dece4e565c.jpg',
                    'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=239553082,2832910159&fm=115&gp=0.jpg',
                    'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2358570013,1985123782&fm=26&gp=0.jpg',
                    'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2914575322,940354749&fm=115&gp=0.jpg',
                    'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3065463705,1034625646&fm=115&gp=0.jpg',
                    'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=577097343,3406258596&fm=26&gp=0.jpg',
                    "http://pic1.win4000.com/mobile/2018-09-04/5b8dece5b9dbe.jpg",
                    "http://pic1.win4000.com/mobile/2018-09-04/5b8dece9ee511.jpg"
                ],//下面图片显示
            };
        },
        onLoad() {},
        methods: {
            getIndex(e) {
                this.activeIndex = e;
            }
        }
    };
</script>

  • CSS

page{
        background-color: #FAFAFA;
    }
    .contentList {
        width: 750upx;
        height: 500px;
        margin-top: 20upx;
    }
    .contentList image {
        width: 100%;
        height: 100%;
    }
    .slidingMenu{
        
    }

  • 最后附上haversterSlidingMenu.vue

<template>
    <scroll-view class="uni-slidingMenu" scroll-x :style="{background: color}">
        <view  :class="['slidingMenuList',activeIndex==index?'active':'']" v-for="(item, index) in list" :key="index" @click="getActive(index)" v-cloak>{{ item }}</view>
    </scroll-view>
</template>

<script>
export default {
    name: 'uniSlidingMenu',
    props:{
        // 列表菜单
        list:{
            type: Array,
            // default:['首页1', '首页2', '首页3', '首页4', '首页4', '首页4', '首页4', '首页4']
        },
        color:{
            type:String,
            default:'#777777'
        }
        
    },
    data() {
        return {
            // list: ['首页1', '首页2', '首页3', '首页4', '首页4', '首页4', '首页4', '首页4'],
            activeIndex:"0"
        };
    },
    methods:{
        getActive(index){
            this.activeIndex=index;
            this.$emit("changes",this.activeIndex);
        }
    }
};
</script>

<style>
    page{
        background-color: #fafafa;
    }
/* 滑动菜单栏的总内容区域 */
.uni-slidingMenu {
    width: 100%;
    white-space: nowrap;
    height: 80rpx;
    background-color: #FFFFFF;
}
/* 循环显示的菜单栏 */
.slidingMenuList {
    height: 80rpx;
    line-height: 80rpx;
    display: inline-block;
    font-size: 24rpx;
    margin-left: 60rpx;
}
.slidingMenuList:last-child{
    margin-right: 60rpx;
}
/* 点击选中菜单栏时的样式 */
.active {
    color: pink;
    font-size: 28rpx;
    margin-left: 80rpx;
    border-bottom: 2rpx solid pink;
    box-sizing: border-box;
}
</style>

转载于:https://www.cnblogs.com/neo-java/p/11459492.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值