Vue路由及嵌套路由

router.js

import Vue from ‘vue‘
import VueRouter from ‘vue-router‘

Vue.use(VueRouter)

const first = {template:‘<h1>first</h1>‘}
const second = {template:‘<h1>second</h1>‘}
const home = {template:‘<h1>home</h1>‘}
const lala = {
template:`
<div class="lala">
<h2>组件</h2>
<router-view class="lalala"></router-view>
</div>
`
}
const firstfirst = {template:‘<h1>firstfirst</h1>‘}
const secondsecond = {template:‘<h1>secondsecon</h1>‘}

const router=new VueRouter({
mode:‘history‘,
base:__dirname,
routes:[
{path:‘/‘, component:home},
{path:‘/first‘, component:lala,
children:[
{path:‘/first‘, component:firstfirst},
{path:‘/second‘, component:secondsecond}
]
},
{path:‘/second‘, component:second}
]
})
new Vue({
router,
template:` <div id="r">
<h1>导航</h1>
<ol>
<li><router-link to = "/">/</router-link></li>
<li><router-link to = "/first">first</router-link></li>
<ol>
<li><router-link to = "/first">first</router-link></li>
<li><router-link to = "/second">second</router-link></li>
</ol>
<li><router-link to = "/second">second</router-link></li>
</ol>
<router-view> </router-view>
</div>

`}).$mount(‘#app‘)

时间: 2024-08-06 22:13:26

Vue路由及嵌套路由的相关文章

vue之vue-router嵌套路由

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

15.前端路由router-05嵌套路由

1.实例化vue,组件APP 2.组件APP路由下,两个字路由children:[] 定义 3.对应页面 原文地址:https://www.cnblogs.com/sunny666/p/11113357.html

Vue开发之基础路由

1.router-link和router-view组件 src/App.vie文件内容: <template> <div id="app"> <div id="nav"> <router-link to="/">Home</router-link> | <router-link to="/about">About</router-link> &

vue嵌套路由

在实际项目中我们会碰到多层嵌套的组件组合而成,但是我们如何实现嵌套路由呢?因此我们需要在 VueRouter 的参数中使用 children 配置,这样就可以很好的实现路由嵌套. index.html,只有一个路由出口 1 <div id="app"> 2 <!-- router-view 路由出口, 路由匹配到的组件将渲染在这里 --> 3 <router-view></router-view> 4 </div> main.

vue 嵌套路由,router-link-active的问题

最近开发的过程中,遇到一个嵌套路由的问题,需求是这这样的, 首页三个路由   a    b    c 路由写法是 export default new Router({ routes: [ // { // path: '/', // component: '' // }, // { // path: '/history-grade', // component: '' // }, { path: '/source-setting', component: setting, children: [

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温习:nextTick、$refs、嵌套路由、keep-alive缓存、is特性、路由属性用法、路由钩子函数

一.$nextTick 1.vue的dom执行异步更新,只要观察到数据变化,vue将开启一个队列,并缓冲在同一事件循环中发生的所有数据改变. 2.vue.$nextTick(cb),数据发生变化,更新dom后执行回调 二.$refs用法 1.ref作用于普通元素——得到dom节点 2.ref作用于子组件——得到组件实例,可使用组件所有方法 3.当v-for用于元素或组件的时候,refs将是包含dom节点或组件实例的数组(想得到单个的ref,只需循环即可) 三.vue组件hover事件模拟 1.m

vue 嵌套路由

在一个页面中如果想实现三个页面的拼接组成一个页面,这时候就用到嵌套路由了. 第一种方法: 1.顶部页面  /views/Home.vue <template> <el-container> <!-- 顶部 --> <el-header class="headerAll"> <div class="headImage"></div> <!-- <img src=""

Vue 嵌套路由、路由守卫

嵌套路由 嵌套路由:一个路由配置中嵌套其他的路由配置. 嵌套路由挺常用的,比如导航栏有首页.文章.想法.留言4个模块,我们以嵌套路由的形式集成这些模块,在导航栏中点击对应的条目,就会路由到对应的页面(下方显示对应的页面),和html的<iframe>效果差不多. demo   嵌套路由 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title><