zoukankan      html  css  js  c++  java
  • vue中嵌套路由的基本使用

      <div id="app">
        <router-link to="/home">首页</router-link>
        <router-link to="/user">用户管理</router-link>
    
        <router-view></router-view>
      </div>
    
      <script src="./vue.js"></script>
      <script src="./vue-router.js"></script>
      <script>
        const Home = {
          template: `
            <h1>这是 Home 组件</h1>
          `
        }
    
        // 父组件:
        const User = {
          template: `
            <div class="user">
              <h2>用户中心</h2>
              <router-link to="/user/profile">个人资料</router-link>
              <router-link to="/user/posts">岗位</router-link>
    
              <!-- 子路由展示在此处 -->
              <router-view></router-view>
            </div>
            `
        }
    
        // 子组件:
        const UserProfile = {
          template: '<h3>个人资料:张三</h3>'
        }
        const UserPosts = {
          template: '<h3>岗位:FE</h3>'
        }
    
        const router = new VueRouter({
          routes: [
            {
              path: '/home',
              component: Home
            },
    
            {
              path: '/user',
              component: User,
              // 子路由配置:
              children: [
                {
                  // 当 /user/profile 匹配成功,
                  // UserProfile 会被渲染在 User 的 <router-view> 中
                  path: 'profile',
                  component: UserProfile
                },
                {
                  // 当 /user/posts 匹配成功
                  // UserPosts 会被渲染在 User 的 <router-view> 中
                  path: 'posts',
                  component: UserPosts
                }
              ]
            }
          ]
        })
    
        const vm = new Vue({
          el: '#app',
          data: {
    
          },
    
          router
        })
      </script>
    
  • 相关阅读:
    归并排序
    快速排序
    UNION与UNION ALL的区别
    聚集索引和非聚集索引
    设计模式之抽象工厂模式
    list中map 的value值时间排序
    webmvc 拦截器 允许跨域 跨域问题 sessionid不一样
    redis 主从复制 和集群
    maven打包
    bcprov-jdk15on包用于创建CSR(证书请求)
  • 原文地址:https://www.cnblogs.com/mushitianya/p/10531458.html
Copyright © 2011-2022 走看看