項目之頭部選項卡

做出效果如下


微信截圖_20181109005128.png

我們需要用到一個第三方插件

npm i ly-tab -S

因為這個插件是在全局中使用的,因此需要在全局的main.js文件下引入

import LyTab from 'ly-tab'
Vue.use(LyTab);

因為只有在Home這個頁面上才有用到,所以我們在Home這個路由上配置即可

<template>
    <div class="home">
        <ly-tab
         v-model="selectedId"
         :items="items"
         :options="options"
         

         class="fix"
        />
        <router-view></router-view>
    </div>
</template>

<script>

    export default{
        name:"Home",
        data(){
            return{
                selectedId:0,
                items:[
                    {label:'熱門'},
                    {label:'服飾'},
                    {label:'鞋包'},
                    {label:'母嬰'},
                    {label:'百貨'},
                    {label:'食品'},
                    {label:'內(nèi)衣'},
                    {label:'男裝'},
                    {label:'電器'}
                ],
                options:{
                    activeColor:'#e9232c',
                },
                subRouteUrl:['/home/hot','/home/dress','/home/box',
                '/home/mbaby','/home/general','/home/food','/home/shirt',
                '/home/man','/home/ele']
            }
        },
        methods:{
            handleChange(item,index){
                this.$router.replace(this.subRouteUrl[index]);
            }
        }
    }


</script>

<style scoped lang="stylus" ref="stylesheet/stylus">
.home
    background #f5f5f5
    width 100%
    height 100%

    .fix
        position fixed
        left 0
        top 0
        z-index 998
</style>

因為存在2級路由關(guān)系,所以在home路由下創(chuàng)建以下子路由


微信截圖_20181109011713.png

然后在路由配置項中進(jìn)行配置

import Hot from './../pages/Home/Children/Hot/Hot'
import Dress from './../pages/Home/Children/Dress'
import Ele from './../pages/Home/Children/Ele'
import Food from './../pages/Home/Children/Food'
import General from './../pages/Home/Children/General'
import Box from './../pages/Home/Children/Box'
import Man from './../pages/Home/Children/Man'
import Mbaby from './../pages/Home/Children/Mbaby'
import Shirt from './../pages/Home/Children/Shirt'

export default new VueRouter({
    //3.1 配置一級路由
    routes:[
        {
            path:'/home',
            component:Home,
            children:[
                {path:'hot',component:Hot},
                {path:'box',component:Box},
                {path:'dress',component:Dress},
                {path:'ele',component:Ele},
                {path:'food',component:Food},
                {path:'general',component:General},
                {path:'man',component:Man},
                {path:'shirt',component:Shirt},
                {path:'mbaby',component:Mbaby},
                {path:'/home',redirect:'/home/hot'}
            ]
        },

解釋代碼難點(diǎn)部分

1.ly-tab這個上面各種看不懂的東西,都是組件自己要求配置的選項,比如v-model:'selectedID',就是組件規(guī)定選中的哪個地方的東西,0就是默認(rèn)選中第一個,option配置的是選中時字體的顏色
2.@change="handleChange" @change是組件規(guī)定的方法,后面方法名字自己定義即可,方法默認(rèn)自帶兩個參數(shù),一個item是選中的項,一個index是選中的索引

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,034評論 25 709
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,554評論 19 139
  • Spring Boot 參考指南 介紹 轉(zhuǎn)載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 47,273評論 6 342
  • 用兩張圖告訴你,為什么你的 App 會卡頓? - Android - 掘金 Cover 有什么料? 從這篇文章中你...
    hw1212閱讀 13,990評論 2 59
  • 一天,小螞蟻正正在森林散步。突然,大象壯壯闖過來,擋住了螞蟻正正的路。 螞蟻正正說:“大塊頭,你沒事找事呀,我告訴...
    無敵小品子閱讀 1,013評論 5 44

友情鏈接更多精彩內(nèi)容