###### 问题遇到的现象和发生背景嵌套路由会到转到新页面,而不是router-view的位置
###### 问题相关代码,请勿粘贴截图
这是index.vue代码
<template>
<el-container>
<el-header>
<span>向日葵点餐系统</span>
<el-button>默认按钮</el-button>
</el-header>
<el-container>
<el-aside width="200px">
<el-col :span="12" width="200px">
<el-menu
default-active="1"
class="el-menu-vertical-demo"
@open="handleOpen"
@close="handleClose"
background-color="#545c64"
text-color="#fff"
active-text-color="#ffd04b"
>
<el-menu-item index="1" @click="tobaseInfo">
<i class="el-icon-menu"></i>
<span slot="title">基本信息</span>
</el-menu-item>
<el-submenu index="2">
<template slot="title">
<i class="el-icon-location"></i>
<span>店铺设置</span>
</template>
<el-menu-item-group>
<el-menu-item index="2-1" @click="toindexImg"
>主页图片</el-menu-item
>
<el-menu-item index="2-2" @click="togoodsInfo"
>菜品信息</el-menu-item
>
<el-menu-item index="2-3" @click="togoodsClass"
>菜品分类</el-menu-item
>
</el-menu-item-group>
</el-submenu>
<el-menu-item index="3" @click="toorders">
<i class="el-icon-document"></i>
<span slot="title">订单信息</span>
</el-menu-item>
<el-menu-item index="4">
<i class="el-icon-setting"></i>
<span slot="title">导航四</span>
</el-menu-item>
<el-menu-item index="5">
<router-link to="/index/indexImg">dasdadas</router-link>
</el-menu-item>
</el-menu>
</el-col>
</el-aside>
<el-main>
<router-view> </router-view>
</el-main>
</el-container>
</el-container>
</template>
<script>
export default {
methods: {
handleOpen(key, keyPath) {
console.log(key, keyPath);
},
handleClose(key, keyPath) {
console.log(key, keyPath);
},
tobaseInfo() {
this.$router.push("/index/baseInfo");
},
toindexImg() {
this.$router.push("/index/indexImg");
},
togoodsInfo() {
this.$router.push("/index/goodsInfo");
},
togoodsClass() {
this.$router.push("/index/goodsClass");
},
toorders() {
this.$router.push("/index/orders");
},
},
};
</script>
<style lang="less" scoped>
.el-header {
background-color: #b3c0d1;
color: #333;
text-align: center;
line-height: 60px;
display: flex;
justify-content: space-between;
align-items: center;
}
.el-aside {
background-color: #d3dce6;
color: #333;
text-align: center;
line-height: 200px;
height: 100%;
height: calc(100vh - 60px);
.el-col {
width: 100%;
float: none;
}
}
.el-main {
background-color: #e9eef3;
color: #333;
text-align: center;
line-height: 160px;
}
.title {
width: 200px;
}
</style>
这是路由的js
import Vue from "vue";
import VueRouter from "vue-router";
import login from "../components/login.vue";
import register from "../components/register.vue";
import retrievePwd from "../components/retrievePwd.vue";
import index from "../components/index.vue";
import goodsInfo from "../components/goods/goodsInfo.vue";
import goodsClass from "../components/goods/goodsClass.vue";
import baseInfo from "../components/index/baseInfo.vue";
import indexImg from "../components/index/indexImg.vue";
import orders from "../components/orders/orders.vue";
Vue.use(VueRouter);
const routes = [
{
path: "/login",
name: "login",
component: login,
},
{
path: "/register",
name: "register",
component: register,
},
{
path: "/retrievePwd",
name: "retrievePwd",
component: retrievePwd,
},
{
path: "/index",
name: "index",
component: index,
childer: [
{ path: "goodsInfo", component: goodsInfo },
{ path: "goodsClass", component: goodsClass },
{ path: "baseInfo", component: baseInfo },
{ path: "indexImg", component: indexImg },
{ path: "orders", component: orders },
],
},
{
path: "/",
redirect: "/index",
},
];
const router = new VueRouter({
mode: "history",
base: process.env.BASE_URL,
routes,
});
export default router;
###### 运行结果及报错内容
###### 我的解答思路和尝试过的方法
###### 我想要达到的结果