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" content="ie=edge">
<title>嵌套router</title>
<script src="./lib/vue-2.4.0.js"></script>
<script src="./lib/vue-router-3.0.1.js"></script>
</head>
<body> <div class="container">
<!-- 符组件的连接指向了denglu路径 -->
<router-link to="/denglu">显示</router-link>
<router-view></router-view>
</div> <template id="account">
<div>
<h1>这个是一个组件</h1>
<!-- 子组件的连接要指向denglu路径下的longin路径 -->
<router-link to="/denglu/login">登录</router-link>
<router-link to="/denglu/zhuce">注册</router-link>
<router-view></router-view>
</div>
</template> <script>
var box={
template:'#account'
} var login={
template:'<h1>登录</h1>'
} var zhuce={
template:"<h1>注册</h1>"
}
var router=new VueRouter({
routes: [
// 路由规则主路径 指向了denglu 子路径使用children 属性,
//实现子路由,同时,子路由的 path 前面,不要带 / ,否则永远以根路径开始请求,这样不方便我们用户去理解URL地址
{path:'/denglu',component:box,children:[
{path:"login",component:login},
{path:"zhuce",component:zhuce},
]},
]
}) var vm=new Vue({
el:".container",
data:{},
router
})
</script>
</body>
</html>
命名视图(就是给router-view 添加一个name属性)
<!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" content="ie=edge">
<title>Document</title>
<script src="./lib/vue-2.4.0.js"></script>
<script src="./lib/vue-router-3.0.1.js"></script>
</head>
<body>
<div class="container">
<router-view name="header"></router-view>
<div class="aa">
<router-view name="left"></router-view>
<router-view name="mian"></router-view>
</div> </div> <!-- 添加样式 -->
<style>
.box{
padding: 0;
margin: 0;
}
h1{
padding: 0;
margin: 0;
}
.headerbox{
background-color: green;
}
.aa{
display: flex;
height: 600px;
} .leftbox{
flex:2;
background-color: hotpink;
} .mianbox{
flex:8;
background-color: indigo;
} </style> <script> var heaer={
template:"<h1 class='headerbox'>这是网页的头部</h1>"
} var leftbox={
template:"<h1 class='leftbox'>这是网页的侧边栏</h1>"
} var mianbox={
template:"<h1 class='mianbox'>这是网页的主体</h1>"
} var router=new VueRouter({
routes: [
{path:'/',components:{
header:heaer,
left:leftbox,
mian:mianbox
}}
]
}) var vm=new Vue({
el:".container",
data:{},
router:router
}) </script>
</body>
</html>
Vue路由嵌套和命名视图的更多相关文章
- vue路由5:命名视图
<div id="app"> <div> <router-link to="/">首页</router-link> ...
- Vue路由嵌套
Vue路由嵌套 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- vue 路由嵌套 及 router-view vue-router --》children
vue 路由嵌套 vue-router -->children 在项目的很多子页面中,我们往往需要在同一个页面做一个组件的切换,同时保存这个页面的部分数据(比如树形菜单),进而显示不同的数据 ...
- 062——VUE中vue-router之命名视图的实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue 路由嵌套高亮问题
正常路由嵌套是没有问题的,但是如果你已经在当前主路由页面了,然后再次点击主路由就会出现页面数据空白的情况 看代码: //主路由通过v-for循环出来 <div class="list- ...
- vue路由嵌套,对应展示的视图
- vue教程3-06 vue路由嵌套(多层路由),路由其他信息
多层嵌套: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- vue路由--嵌套路由
静态嵌套路由: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- vue路由嵌套,vue動態路由
https://www.cnblogs.com/null11/p/7486735.html https://www.cnblogs.com/goloving/p/9271501.html https: ...
随机推荐
- 查看所使用的Linux系统是32位还是64 位的方法
方法一:getconf LONG_BIT # getconf LONG_BIT 1 1 我的Linux是32位!!! 方法二:arch # arch 1 1 显示 i686 就是32位,显示 x86_ ...
- 将PCM格式存储成WAV格式文件
将PCM格式存储成WAV格式文件 WAV比PCM多44个字节(在文件头位置多) 摘自:https://blog.csdn.net/u012173922/article/details/78849076 ...
- oraagent.bin High Memory Usage as Dependent Listener was Removed/Renamed
Grid Infrastructure oraagent.bin process using huge amount of memory and forking huge number of thr ...
- 基于Python的WEB接口开发与自动化测试 pdf(内含书签)
基于Python的WEB接口开发与自动化测试 目录 目 录O V目 录章 Python 学习必知 ................................................... ...
- 【源码解析】Flink 是如何基于事件时间生成Timestamp和Watermark
生成Timestamp和Watermark 的三个重载方法介绍可参见上一篇博客: Flink assignAscendingTimestamps 生成水印的三个重载方法 之前想研究下Flink是怎么处 ...
- 【Leetcode_easy】1022. Sum of Root To Leaf Binary Numbers
problem 1022. Sum of Root To Leaf Binary Numbers 参考 1. Leetcode_easy_1022. Sum of Root To Leaf Binar ...
- 【Leetcode_easy】997. Find the Town Judge
problem 997. Find the Town Judge solution: class Solution { public: int findJudge(int N, vector<v ...
- 原生JavaScript常用本地浏览器存储方法五(LocalStorage+userData的一个浏览器兼容类)
基于LocalStorage+globalStorage+userData实现的一个本地存储类 userData用来兼容ie6 ie7 由userData模仿Session的方法:浏览器关闭删除保存的 ...
- 设计模式之--Visitor
Ref: https://www.jianshu.com/p/feec47a25b67 https://www.cnblogs.com/alphablox/p/5346567.html
- 《ucore lab1》实验报告
资源 ucore在线实验指导书 我的ucore实验代码 练习1:理解通过make生成执行文件的过程 详见<ucore lab1 exercise1>实验报告 练习2:使用qemu执行并调试 ...