要求如下图
解决方式一
HomeView.vue 更改
<template>
<div class="home">
<el-container>
<el-header></el-header>
<el-main>
<el-form :model="data_form" label-width="120px">
<el-button type="primary" @click="toParent()">PM主表数据匹配</el-button>
<el-button type="primary" @click="toChild()">PM子表数据匹配</el-button>
</el-form>
</el-main>
<div id="app">
<router-view v-slot="{ Component }">
<keep-alive>
<component :is="Component" />
</keep-alive>
</router-view>
</div>
</el-container>
</div>
</template>
参考依据
vue-router 官方文档
解决方式二(这种方式现在废弃了,使用可能不生效,废弃原因参考官方文档)
router路由 下 index.js 更改
import { createRouter, createWebHashHistory } from "vue-router";
import HomeView from "../views/HomeView.vue";
import PmFInsert from "../components/pm_f_insert.vue"
import PmFSelect from "../components/pm_f_select.vue"
import PmChild from "../components/pm_child.vue"
const routes = [
{
path: "/",name: "home",component: HomeView,
children:[
{path:'/',redirect:'PmFInsert'},
{
path:'PmFInsert',
name:'home_f',
component:PmFInsert,
meta:{keepAlive:true}
},
{
path:'PmFSelect',
name:'f_select',
component:PmFSelect,
meta:{keepAlive:false}
},
{
path:'PmChild',
name:'c_home',
component:PmChild ,
meta:{keepAlive:false}
}
]
},
];
const router = createRouter({
history: createWebHashHistory(),
routes
});
export default router;