美文网首页
vue 导航路由的嵌套写法

vue 导航路由的嵌套写法

作者: 温柔vs先生 | 来源:发表于2021-06-30 14:08 被阅读0次

路由:

import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);


const Content = () => import("../views/Content.vue");
const Home = () => import("../views/Home.vue");
const About = () => import("../views/About.vue");
const Detail = () => import("../views/Detail.vue");


const routes = [
    {
        path: "",
        redirect: "/content"
    },
    {
        path: "/content",
        name: "Content",
        component: Content,
        children: [
            {
                path: "",
                redirect: "/content/home"
            },
            {
                path: '/content/home',
                component: Home
            },
            {
                path: '/content/About',
                component: About
            }
        ]
    },
    {
        path: "/detail",
        name: "Detail",
        component: Detail
    },
];


const router = new VueRouter({
    routes
})

export default router

app.vue:

<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: "App",
  components: {},
};
</script>

<style>
html,
body {
  height: 100%;
  margin: 0;
}
#app {
  height: 100%;
}
</style>

main.js:

import Vue from 'vue'
import App from './App.vue'
import router from './router'

Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App),
}).$mount('#app')

content.vue

<template>
  <div id="content">
    <div class="content-view"><router-view /></div>

    <div class="table-bar">
      <div @click="goHome">首页</div>
      <div @click="goAbout">关于</div>
    </div>
  </div>
</template>

<script>
export default {
  methods: {
    goHome() {
      this.$router.replace("/content/home");
    },
    goAbout() {
      this.$router.replace("/content/about");
    },
  },
};
</script>

<style scoped>
#content {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.content-view {
  flex: 1;
}
.table-bar {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  height: 49px;
}
</style>>

home:

<template>
  <div id="home">
    <div @click="goDetail">首页</div>
  </div>
</template>

<script>
export default {
  methods: {
    goDetail() {
      this.$router.push("/detail");
    },
  },
};
</script>

<style scoped>
</style>

about:

<template>
  <div id="about">关于</div>
</template>

<script>
export default {};
</script>

<style scoped>
</style>>

detail:

<template>
  <div id="detail">详情</div>
</template>

<script>
export default {};
</script>

<style scoped>
</style>>

相关文章

  • 8月第二周

    8.7 vue-cli vue-router 用法总结: 包含默认路由的地址写法,父子路由的嵌套,redirec...

  • Vue 记事

    嵌套路由简易写法 Vue setInterval 使用 Vue 组件中添加监听 添加监听: handleGloba...

  • vue 导航路由的嵌套写法

    路由: app.vue: main.js: content.vue home: about: detail:

  • 3、制作左右结构导航首页

    目标 期待效果 layout.vue布局页面开发 嵌套路由 NavMenu 导航菜单 测试 期待效果 左侧导航,右...

  • 制作左右结构导航页

    目标 期待效果 layout.vue布局页面开发 嵌套路由 NavMenu 导航菜单 测试 期待效果 左侧导航,右...

  • 3.路由vue-router

    设置路由 两种写法 路由跳转 嵌套路由

  • vue路由

    路由:vue-router 案例: 1.路由 2.路由的嵌套

  • 1、首页

    首页左右结构,加导航菜单 效果图 嵌套路由,点击左侧实现右侧展示 1、开发userIndex.vue(简单页面 ...

  • Vue应用

    Vue项目 Vue结构 Vue项目打包与发布 Vue语法二 Vue网络请求 Vue路由 动态路由 编程式路由导航

  • vue嵌套路由与404重定向实现方法分析

    第一部分: vue嵌套路由 嵌套路由是什么? 嵌套路由就是在一个被路由过来的页面下可以继续使用路由,嵌套也就是路由...

网友评论

      本文标题:vue 导航路由的嵌套写法

      本文链接:https://www.haomeiwen.com/subject/czqrultx.html