vue路由的配置和頁面切換詳解
1.vue路由
可以實現(xiàn)單頁面應用。
路由三要素:
vue路由通過hash的變化切換頁面(組件/div)
<router-link>導航
<router-view>存儲頁面(組件)的容器
src/router/index.js路由的配置
實現(xiàn)步驟:
2.router配置
對router文件夾下的index.js進行配置
path:url
name:對應的參數(shù)的模塊名稱
component:組件名
用組件時一定要注冊
{ path: '/product', name: 'Product', component: Product }
3.實現(xiàn)傳參配置
配置
{ path: '/product/:id', name: 'Product', component: Product }
切換: <router-link to="/product/666">
產(chǎn)品666</router-link>
接收: {{$route.params.id}}
4 子頁面
配置
{ path: '/admin', name: 'Admin', component: Admin, children:[ {path:"ucenter",component:Ucenter}, {path:"activity",component:Activity}, {path:"",redirect:"ucenter"}//重定向 ] },
重定向: {path:"",redirect:"ucenter"}
創(chuàng)建新的別名: alias:["/home","/main"]
切換: <router-link to="/admin/ucenter"></router-link>
5 頁面切換
跳轉(zhuǎn):$router.go(-1)
后退:$router.back()
前進: ```$router.forward()``
新加歷史記錄切換頁面:$router.push()
替換當前頁面(不留歷史記錄):$router.replace()
總結(jié)
到此這篇關于vue路由的配置和頁面切換的文章就介紹到這了,更多相關vue路由的配置和頁面切換內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
在vue中路由使用this.$router.go(-1)返回兩次問題
這篇文章主要介紹了在vue中路由使用this.$router.go(-1)返回兩次問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12vue axios數(shù)據(jù)請求及vue中使用axios的方法
axios 是一個基于Promise 用于瀏覽器和 nodejs 的 HTTP 客戶端,在vue中數(shù)據(jù)請求需要先安裝axios。這篇文章主要介紹了vue axios數(shù)據(jù)請求及vue中使用axios的方法,需要的朋友可以參考下2018-09-09