vue-router 路由傳參用法實(shí)例分析
本文實(shí)例講述了vue-router 路由傳參用法。分享給大家供大家參考,具體如下:
在設(shè)置路由規(guī)則時(shí),我們可以給路徑名設(shè)置一個(gè)別名,方便進(jìn)行路由跳轉(zhuǎn),而不需要去記住過長的全路徑。
例如:
<%@ 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> <template id="users"> <div class="container"> <h1> this is list page----{{$route.path}}</h1> <h2>用戶信息</h2> <router-link to="/list/user/001">用戶{{$route.params.id}}</router-link> <router-link to="/list/user/002">用戶{{$route.params.id}}</router-link> </div> </template> <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:'#users', }, }, { path:'/list/user/:id', component:{ template: '<h3>用戶Id{{$route.params.id}} </h3>' } } ] }); const app = new Vue({ router:router }).$mount('#app') </script> </body> </html>
上文中的 importFile,jsp 在上一篇路由基本用法中介紹過了,就是引入需要的文件。
希望本文所述對大家vue.js程序設(shè)計(jì)有所幫助。
相關(guān)文章
vue之父子組件間通信實(shí)例講解(props、$ref、$emit)
組件間如何通信,也就成為了vue中重點(diǎn)知識(shí)了。這篇文章將會(huì)通過props、$ref和 $emit 這幾個(gè)知識(shí)點(diǎn),來講解如何實(shí)現(xiàn)父子組件間通信。2018-05-05vue綁定數(shù)字類型 value為數(shù)字的實(shí)例
這篇文章主要介紹了vue綁定數(shù)字類型 value為數(shù)字的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08vue js秒轉(zhuǎn)天數(shù)小時(shí)分鐘秒的實(shí)例代碼
這篇文章主要介紹了vue js秒轉(zhuǎn)天數(shù)小時(shí)分鐘秒的實(shí)例代碼,代碼簡單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-08-08vue循環(huán)數(shù)組改變點(diǎn)擊文字的顏色
這篇文章主要為大家詳細(xì)介紹了vue循環(huán)數(shù)組改變點(diǎn)擊文字的顏色,非常實(shí)用的切換效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-10-10vue?項(xiàng)目優(yōu)雅的對url參數(shù)加密詳解
這篇文章主要為大家介紹了vue?項(xiàng)目優(yōu)雅的對url參數(shù)加密詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10詳解Vue前端生產(chǎn)環(huán)境發(fā)布配置實(shí)戰(zhàn)篇
這篇文章主要介紹了詳解Vue前端生產(chǎn)環(huán)境發(fā)布配置實(shí)戰(zhàn)篇,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-05-05Vue2中使用axios的3種方法實(shí)例總結(jié)
axios從功能上來說就是主要用于我們前端向后端發(fā)送請求,是基于http客戶端的promise,面向?yàn)g覽器和nodejs,下面這篇文章主要給大家介紹了關(guān)于Vue2中使用axios的3種方法,需要的朋友可以參考下2022-09-09vue3實(shí)現(xiàn)監(jiān)聽store中state狀態(tài)變化的簡單方法
這篇文章主要給大家介紹了關(guān)于vue3實(shí)現(xiàn)監(jiān)聽store中state狀態(tài)變化的簡單方法,store是一個(gè)狀態(tài)管理工具,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-10-10