vue之路由嵌套,子路由

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <script src="js/vue.js"></script>
    <script src="js/vue-router.js"></script>
    <title>Title</title>
</head>
<body>

<div id="app">
    <router-link to="/home">主页</router-link>
    <router-link to="/user">用户</router-link>

    <router-view></router-view>
</div>

<template id="user">
    <div>
        <h1>用户信息</h1>
        <ul>
            <li><router-link to="/user/regist">用户注册</router-link></li>
            <li><router-link to="/user/login">用户登录</router-link></li>
        </ul>

        <router-view></router-view>
    </div>

</template>

</body>

<script>
    var home={
        template:'<h1>home</h1>'
    };
    var user={
        template:'#user'
    };

    let login={
        template:'<h1>登录中....</h1>'
    };
    let regist={
        template:"<h1>注册</h1>"
    }
    const routes1=[
        {path:'/home',component:home},
        {path:'/user',component:user,
        children:[
            {
            path: 'login',
            component: login,
            },
            {
             path:'regist',
             component:regist
            }
        ]},
        // {path:'*',redirect:'/home'}
    ];
    const router = new VueRouter({
        routes:routes1,
    });
    new Vue({
        el:'#app',
        router
    })
</script>

</html>

原文地址:https://www.cnblogs.com/wspblog/p/10273371.html

时间: 2024-07-31 03:21:41

vue之路由嵌套,子路由的相关文章

angular2系列教程(十一)路由嵌套、路由生命周期、matrix URL notation

今天我们要讲的是ng2的路由的第二部分,包括路由嵌套.路由生命周期等知识点. 例子 例子仍然是上节课的例子: 上节课,我们讲解了英雄列表,这节课我们讲解危机中心. 源代码: https://github.com/lewis617/angular2-tutorial/tree/gh-pages/router 运行方法: 在根目录下运行: http-server 路由嵌套 我们在app/app.component.ts中定义了路由url和视图组件,其中包括这样一项: app/app.componen

vue之路由的嵌套 子路由

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" con

Vue中使用children实现路由的嵌套

Vue中使用children实现路由的嵌套 相关Html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv=&

Vue学习手记03-路由跳转与路由嵌套

1.路由跳转 添加一个LearnVue.vue文件, 在router->index.js中 引入import Learn from '@/components/LearnVue' 在touter中添加路由说明 export default new VR({ routes:[ { path:"/hello", name:"HelloWorld", component:HelloWorld }, { path:"/learn", name:&q

vue之vue-router嵌套路由

1.定义路由 routes: [ { path: '/product', //第一层路由 name: 'product', component: Vproductcontent,//父组件渲染的是子组件的内容<routerview/>写在父组件中 children:[ { path: '/product/hotproduct', //第二层路由 name: 'hotproduct', component: Vhotproduct, children:[ { path: '/product/ho

vue之路由以及默认路由跳转

vue之路由以及默认路由跳转 之前我们将子组件挂载到根组件的时候都是手动挂载的,而路由就是自动的将子组件挂载到根组件中 在这里我们需要用到一个路由插件,就是 vue-router ,vue-router网址:https://router.vuejs.org/zh/guide/ 既然要用插件了那肯定要先安装啦. vue-router使用步骤: 1.安装vue-router    官网有说明 注意:安装时最好加上 --save  ,让其加入到package.js包中,方便被人使用.也可以使用cnpm

vue学习笔记——vue-router(路由)

使用路由的时候有两个必要的知识:<router-link></router-link>:这个相当于a标签,点击的切换时候的按钮,<router-view></router-view>:这个就是你加载过来的组件放的位置 使用方法: 1.cnpm install vue-router --save 下载路由 2.在main.js 里面引入路由:import vueRouter from 'vue-router' 3.定义路由:Vue.use(vueRouter)

vue2.0路由-路由嵌套

vue一个重要的方面就是路由,下面是自己写的一个路由的例子: 1.引入依赖库就不必再说 2.创建组件 两种写法 第一种:间接 <template id="home"> <div> <h1>Home</h1> <p>{{msg}}</p> </div> </template> var About = Vue.extend({ template: '#about' }); 第二种:直接 var

vue2.0路由嵌套

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>vue2.0路由嵌套2</title> <script type="text/javascript" src="js/vue2.0.js" ></script> <script type="text/javascrip