5.7K Star 41.3K Fork 22.5K

GVP若依 / RuoYi

 / 详情

Vue3版本中,自己页面嵌套路由实现局部刷新,怎么实现?

待办的
创建于  
2024-05-10 01:04

输入图片说明

代码结构为test目录下有三个文件(同级文件):index.vue(主界面),one.vue, two.vue.
想实现的效果是点击上图中的router-link,让one.vue和two.vue两个组件显示到router-view里。

输入图片说明
index.vue的代码

<template>
    <!-- test/index 路由坑位页面-->
    <div style="margin: 20px">
        <!-- 头部按钮 -->
        <div style="margin-bottom: 20px">
            <router-link class="link-type" to="/test/nest/one">显示one.vue</router-link>
            &nbsp;&nbsp;&nbsp;
            <router-link class="link-type" to="/test/nest/two">显示two.vue</router-link>
        </div>
        <!-- 路由坑文件 -->
        <div style="width: 80%;height: 500px;border: 1px solid #ccc">
            <router-view></router-view>
        </div>
    </div>
</template>
<script setup>
    import { useRouter } from 'vue-router'
    const router = useRouter()
    console.log("我test/nest/index运行了");
</script>

输入图片说明

输入图片说明
路由配置的代码

{
    path: "/test",
    hidden: true,
    component: Layout,
    children: [
      {
        path: "nest",
        hidden: true,
        meta: { title: '测试', icon: 'user' },
        component: () => import('@/views/test/index'),
        children: [
          { path: "one", component: () => import('@/views/test/one'), hidden: true},
          { path: "two", component: () => import('@/views/test/two'), hidden: true}
        ]
      }
    ]
  }

现有代码点击后也能显示进去,但是整个tab页面进行了刷新,而不是局部刷新。两个链接点击都会再次加载运行index.vue。
我在index.vue里写了句console.log("我test/nest/index运行了"),点一次链接按钮就打印一次,从而可以看出不是局部刷新的。

输入图片说明

评论 (0)

任宏 创建了任务
任宏 修改了描述
任宏 修改了描述
展开全部操作日志

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(1)
Java
1
https://gitee.com/y_project/RuoYi.git
git@gitee.com:y_project/RuoYi.git
y_project
RuoYi
RuoYi

搜索帮助

53164aa7 5694891 3bd8fe86 5694891