请使用插槽vm.$slots实现一个导航栏结构

运行结果如下:

 

 

话不多说,直接开整:

样式如下:

    <style>
        #navga{
            top:0;
            left:0;
            right: 0;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding:0 5vw;
            height: 70px;
            width: 100%;
            background-color: rgba(65,81,101,0.9);      
        }
        .container
        {
            top:0;
            left:0;
            right: 0;
            width: 100%;
            display: flex;
            
            align-items: center;
        }
        .left{
            width:250px; height:100%;
            flex:none;
        }
        .middle{
            
            height: 100%;
            align-items: center;
            text-align: center;
            
            flex:none;
            
        }
        .right{
            height:100%;
            width: 500px;
            
            flex:none;        
        }
        .logotext
        {
            font-size: 28px;
            font-weight: 600;
            color: linear-gradient(to top, #9890e3 0%, #b1f4cf 100%);
            
        }
        .logo
        {
            flex: 1;
        }
        .logo img
        {
            width:35px;
            height:35px;
            border-radius: 10px;
            display: inline-table;
            flex: 1;
            vertical-align: center;
        }
        .serch
        {
            height: 30px;
            border-radius: 10px;
            width: 300px;

        }
        ul
        {
            list-style-type: none;
            margin: 0;
            padding: 0;
            display: inline-flex;
            flex-direction: row;
            justify-content: center;
            align-items: center;
            text-align: center;
            width: 100%;
        }
        li{
            width: 15%;
            flex: 1;
            display: inline;
            align-content: center;
        }
        a 
        {
            text-decoration: none;
            display: inline;
            font-size: 20px;
            font-weight: 300;
            width: 100%;
            color: azure;
            
        }
    </style>

页面结构和js逻辑如下:

<body>
    <div id="app">

        <div id="header">
            <navga id="navga">
                <div class= "container">
                    <div class="left">
                        <div class="logo">
                            <img src="./logo.jpg">
                            <span class="logotext">写bug的猎人</span>
                          </div>
                    </div>
                    <div class="middle">
                        <input type="text" class="serch">
                    </div>
                    <div class="right">
                        <div class="goo">
                            <ul>
                                <li><a href="#">首页</a></li>
                                <li><a href="#">历史记录</a></li>
                                <li><a href="#">消息中心</a></li>
                                <li><a href="#">娱乐中心</a></li>
                                <li><a href="#">关于我们</a></li>
                            </ul>
                        </div>
                        
                    </div>
                </div>
            </navga>
        </div>

    </div>
    <template id="navigator">
        <div>
            <slot></slot>
        </div>
        
    </template>
    <script>
        Vue.component('navga',{
            template:'#navigator'
        })
        var vm = new Vue({
            el:'#app',
            data:{

            }
        })
    </script>
</body>

如有问题或改进欢迎在留言区评论。

最后,原创不易,点个赞再走哦。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值