vue2路由方式--嵌套路由實(shí)現(xiàn)方法分析
本文實(shí)例講述了vue2嵌套路由實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
前面講過了vue2路由基本用法,一般應(yīng)用中的路由方式不會像上述例子那么簡單,往往會出現(xiàn)二級導(dǎo)航這種情況。這時就需要使用嵌套路由這種寫法。
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>routerTest1</title>
<c:import url="importFile.jsp"></c:import>
</head>
<body>
<div id="app">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#" rel="external nofollow" >Brand</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<%--定義跳轉(zhuǎn)的路徑--%>
<li class="active"> <router-link to="/home">Home</router-link></li>
<li> <router-link to="/list">List</router-link></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<!—路由切換組件template 插入的位置 -->
<router-view></router-view>
</div>
</div>
<script type="x-template" id="modalTel">
<div>
<h1> this is home page </h1>
<div>
<ul >
<li>
<router-link to="/home/lists">List</router-link>
</li>
<li>
<router-link to="/home/detail">Detail</router-link>
</li>
</ul>
</div>
<router-view></router-view>
</div>
</script>
<script>
/*
* var Home = Vue.extend({
template:'<h1> this is home page </h1>',
})
* */
/*使用Javascript模板定義組件*/
var Home = Vue.extend({
template:'#modalTel'
})
/*創(chuàng)建路由器實(shí)例*/
const router = new VueRouter({
routes:[
{ path: '/', redirect: '/home' },
{
path:'/home',
component:Home,
/*嵌套下的路由(子路由)*/
children:[
{
path:'/home/lists',
component:{
template:'<h1> this is lists pages</h1>'
},
},
{
path:'/home/detail',
component:{
template:'<h1> this is detail pages</h1>'
},
}
]
},
{
path:'/list',
component:{
/*顯示路由的屬性*/
template:'<h1> this is list page----{{$route.path}}</h1>'
}
}
]
});
const app = new Vue({
router:router
}).$mount('#app')
</script>
</body>
</html>

上文中的 importFile,jsp 在上一篇路由基本用法中介紹過了,就是引入需要的文件。
希望本文所述對大家vue.js程序設(shè)計有所幫助。
相關(guān)文章
antd?vue?表格rowSelection選擇框功能的使用方式
這篇文章主要介紹了antd?vue?表格rowSelection選擇框功能的使用方式,具有很好的參考價值,希望對大家有所幫助。以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。2022-12-12
Vue實(shí)現(xiàn)一個動態(tài)添加行的表格步驟詳解
在Vue組件中定義表格的數(shù)據(jù)模型,通常使用一個數(shù)組來存儲表格的數(shù)據(jù),每一行數(shù)據(jù)可以是一個對象,對象的屬性對應(yīng)表格的列,這篇文章主要介紹了Vue實(shí)現(xiàn)一個動態(tài)添加行的表格步驟詳解,需要的朋友可以參考下2024-05-05
vue+element-ui?校驗(yàn)開始時間與結(jié)束時間的實(shí)現(xiàn)代碼
這篇文章主要介紹了vue+element-ui?校驗(yàn)開始時間與結(jié)束時間的代碼實(shí)現(xiàn),最主要的需求是開始時間不能早于當(dāng)前時間,感興趣的朋友跟隨小編一起看看吧2024-07-07
Vue.js:使用Vue-Router 2實(shí)現(xiàn)路由功能介紹
本篇文章主要介紹了Vue.js:使用Vue-Router 2實(shí)現(xiàn)路由功能介紹,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02

