zoukankan      html  css  js  c++  java
  • Vue路由讲解

    1>router-link和router-view组件

    2>路由配置

    a.动态路由

    import Home from "@/views/Home.vue";
    
    export default [
      {
        path: "/",
        name: "home",
        component: Home
      },
      {
        path: "/about",
        name: "about",
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ "@/views/About.vue")
      },
      {
        path: "/argu/:name",//动态路由
        component: () => import("@/views/argu.vue")
      }
    ];
    <template>
      <div>
        <!-- 拿到动态路由的参数 $route:当前加载页面的路由对象 -->
        {{$route.params.name}}
      </div>
    </template>
    
    <script>
    export default {
      //
    };
    </script>

    b.嵌套路由

    import Home from "@/views/Home.vue";
    export default [
      {
        path: "/",
        name: "home",
        component: Home
      },
      {
        path: "/about",
        name: "about",
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ "@/views/About.vue")
      },
      {
        path: "/argu/:name",
        component: () => import("@/views/argu.vue")
      },
      //嵌套路由的使用
      {
        path: "/parent",
        component: () => import("@/views/parent.vue"),
        children: [
          {
            path: "child",//此处不能加/
            component: () => import("@/views/child.vue")
          }
        ]
      }
    ];

    child.vue:

    <template>
      <div>I am child</div>
    </template>

    c.命名路由

    import Home from "@/views/Home.vue";
    
    export default [
      {
        path: "/",
        name: "home",//加上name属性  命名路由
        component: Home
      },
      {
        path: "/about",
        name: "about",
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ "@/views/About.vue")
      },
      {
        path: "/argu/:name",
        component: () => import("@/views/argu.vue")
      },
      //嵌套路由的使用
      {
        path: "/parent",
        component: () => import("@/views/parent.vue"),
        children: [
          {
            path: "child",
            component: () => import("@/views/child.vue")
          }
        ]
      }
    ];

    d.命名视图

    import Home from "@/views/Home.vue";
    
    export default [
      {
        path: "/",
        name: "home",//加上name属性  命名路由
        component: Home
      },
      {
        path: "/about",
        name: "about",
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ "@/views/About.vue")
      },
      {
        path: "/argu/:name",
        component: () => import("@/views/argu.vue")
      },
      //嵌套路由的使用
      {
        path: "/parent",
        component: () => import("@/views/parent.vue"),
        children: [
          {
            path: "child",
            component: () => import("@/views/child.vue")
          }
        ]
      },
      {
        path: "/named_view",
        //加载多个组件 用复数
        components: {
          default: () => import("@/views/child.vue"),
          email: () => import("@/views/email.vue"),
          tel:()=>import("@/views/tel.vue")
        }
      }
    ];
    <template>
      <div id="app">
        <div id="nav">
          <router-link to="/">Home</router-link>|
          <!-- 命名路由 -->
          <router-link :to="{name:'about'}">About</router-link>
          <!-- <router-link to="/about">About</router-link> -->
        </div>
        <!-- 路由视图组件 -->
        <router-view/>
        <router-view name="email"/>
        <router-view name="tel"/>
      </div>
    </template>

    child.vue

    <template>
      <div>I am child</div>
    </template>

    email.vue

    <template>
      <div>email:07807958@qq.com</div>
    </template>

    tel.vue

    <template>
      <div>tel:18976543210</div>
    </template>

    打开浏览器:http://localhost:8080/#/named_view

     打开调试工具,可以直观的看出各路由:

    3>JS操作路由(编程式导航)

    4>重定向和别名

    import Home from "@/views/Home.vue";
    
    export default [
      {
        path: "/",
        name: "home", //加上name属性  命名路由
        component: Home
      },
      {
        path: "/main",
        // redirect: "/",
    
        // redirect: {
        //   name:"home"
        // }
        
        redirect: to => {
          //console.log(to);
          // return {
          //   name:"home"
          // }
          return '/'
        }
      }
    ];

    console.log(to)输出信息:

    路由别名:

    export default [
      {
        path: "/",
        alias:'/home_page',
        name: "home", //加上name属性  命名路由
        component: Home
      }]
  • 相关阅读:
    17.1.2.1 Advantages and Disadvantages of Statement-Based and Row-Based Replication
    17.1.2 Replication Formats
    Setting the Master Configuration on the Slave
    17.1.1.9 Introducing Additional Slaves to an Existing Replication Environment
    17.1.1.8 Setting Up Replication with Existing Data
    17.1.1.7 Setting Up Replication with New Master and Slaves
    17.1.1.6 Creating a Data Snapshot Using Raw Data Files
    列出display的值,并说明它们的作用
    CSS设置DIV居中
    CSS选择符有哪些?哪些属性可以继承?优先级算法如何计算?
  • 原文地址:https://www.cnblogs.com/qicao/p/10714104.html
Copyright © 2011-2022 走看看