vue导航条+下拉菜单

  • 直接上效果。。。。

  • 刚学vue,所以代码写的比较乱,欢迎朋友指教。

vue导航条+下拉菜单

  • 具体看代码

<template>
    <div class="wrapper" >
         <div class="nav-item" :class='{active: index == nowIndex}' v-for='(tabItem,index) in tabParams' @click='tabToggle(index)'>
             <span :class='{dropdownBtn: index == 0}'  @click='dropdown'>{{tabItem}}</span>
             <ul v-if='index == 0' class="dropdownWrapper" v-show='dropdownActive'>
                <li v-for='(item, index) in dropParams'>{{item}}</li>
            </ul>
         </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                nowIndex: 0,
                dropdownActive: false,
                tabParams: ['政治', '娱乐', '体育', '搞笑'],
                dropParams: ['亚洲', '北美洲', '欧洲', '非洲']
            }
        },
        methods: {
            dropdown: function(){
                console.log(event.target.getAttribute('class'))
                if(event.target.getAttribute('class') === 'dropdownBtn') {
                    this.dropdownActive = !this.dropdownActive;
                }
            },
            tabToggle: function(index){
                this.nowIndex = index;
                if(index === 0){
                    return
                }else {
                    this.dropdownActive = false;
                }
            }
        },
    }
</script>

<style scoped>
    @import './reset.css';
    body {
        min-height: 100%;
    }
    .wrapper {
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .wrapper>div {
        flex: 1;
        text-align: center;
        height: 36px;
        line-height: 36px;
    }
    .dropdownWrapper {
        /*margin-top: 36px;*/
        border: 1px solid #2C3E50;
        font-size: 14px;
    }
    .dropdownWrapper li {
        display: block;
    }

    .nav-item.active {
        background: #e3e3d3;
    }
    .dropdownBtn {
        display: inline-block;
        width: 100%;
        height: 100%;
    }
    .nav-item {
        cursor: pointer;
    }
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值