笑丶日葵 2021-12-23 15:53 采纳率: 41.9%
浏览 399
已结题

为什么嵌套路由会跳转到新页面,而不是router-view位置?

 ###### 问题遇到的现象和发生背景嵌套路由会到转到新页面,而不是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;

 ###### 运行结果及报错内容

 ###### 我的解答思路和尝试过的方法

 ###### 我想要达到的结果

  • 写回答

2条回答 默认 最新

  • 瞎写点 2021-12-23 16:30
    关注

    会跳到新页面是什么意思,不是你绑定的click方法里的要跳转的页面?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 1月2日
  • 已采纳回答 12月25日
  • 创建了问题 12月23日

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入