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

为什么嵌套路由会跳转到新页面,而不是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 如何构建全国统一的物流管理平台?
  • ¥100 ijkplayer使用AndroidStudio/CMake编译,如何支持 rtsp 直播流?
  • ¥20 和学习数据的传参方式,选择正确的传参方式有关
  • ¥15 这是网络安全里面的poem code
  • ¥15 用js遍历数据并对非空元素添加css样式
  • ¥15 使用autodl云训练,希望有直接运行的代码(关键词-数据集)
  • ¥50 python写segy数据出错
  • ¥20 关于线性结构的问题:希望能从头到尾完整地帮我改一下,困扰我很久了
  • ¥30 3D多模态医疗数据集-视觉问答
  • ¥20 设计一个二极管稳压值检测电路