美食杰个人空间效果(子路由切换)

本文介绍了如何在Vue应用中设置动态路由,包括使用`router-view`实现页面跳转,并详细讲述了如何为个人空间的四个子路由(作品、粉丝、关注和收藏)分别调用接口。同时,涵盖了如何通过`tab-click`事件实现路由切换的效果。
摘要由CSDN通过智能技术生成

效果如下
在这里插入图片描述

const Fans = ()=> import(/*wbpackChunkName:"space"*/ '@/views/user-space/fans');
const MenuList = ()=> import(/*wbpackChunkName:"space"*/ '@/views/user-space/menu-list');
// const Register =() => import('@/views/user-login/register');


const router = new Router({
    mode:"history",
    routes:[{
        path:'/',
        name:"Home",
        component:Home
    },
    {
        path:'/detail',
        name:"detail",
        component:Detail
    },
    {
        path:'*',
        name:'noFound',
        title:'未找到',
        redirect:{
            name:'home'
        }
    },
    {
        path:'/login',
        name:'login',
        component:Login,
        meta:{
            login:true
        }
    },
    {
        path:'/space',
        name:'space',
        component:Space,
        redirect:{
            name:'works'
        },
        meta:{
            login:true
        },
        children:[
            {
                path:'works',
                name:'works',
                component:MenuList,
                meta:{
                    login:true
                }
            },
            {
                path:'fans',
                name:'fans',
                component:Fans,
                meta:{
                    login:true
                }
            },
            {
                path:'following',
                name:'following',
                component:Fans,
                meta:{
                    login:true
                }
            },
            {
                path:'collection',
                name:'collection',
                component:MenuList,
                meta:{
                    login:true
                }
            }
            
        ]
    }
    
]
});

然后在个人空间页通过router-view来进行路由的切换效果
在这里插入图片描述然后再请求四个子路由的接口
在这里插入图片描述然后通过我们上面在router-view上绑定的tab-click事件实现此次效果
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值