Vue中vue-router路由使用示例詳解
前言
Vue Router是Vue框架中非常重要的一個(gè)功能。
目標(biāo)
1 單頁(yè)面應(yīng)用與多頁(yè)面應(yīng)用的區(qū)別;
2 vue-router的具體實(shí)現(xiàn)方法;
3 路由模式有哪幾種,有什么區(qū)別;
4 如何進(jìn)行路由守衛(wèi)與路由緩存;
一 路由的概念
概念
Vue Router是Vue提供的路由管理器。將組件與路由一一對(duì)應(yīng)起來(lái),這種對(duì)應(yīng)關(guān)系就路由。
Vue是一個(gè)典型的SPA單頁(yè)面應(yīng)用框架。SPA單頁(yè)面是指網(wǎng)站只有一個(gè)html頁(yè)面,所有的頁(yè)面切換都只在這個(gè)一個(gè)頁(yè)面中完成。不同組件的切換全部交由路由來(lái)完成.
單頁(yè)面應(yīng)用與多頁(yè)面應(yīng)用
在編程開(kāi)發(fā)興起時(shí),多個(gè)html實(shí)現(xiàn)頁(yè)面的切換,這就是早期的MPA多頁(yè)面應(yīng)用。隨著技術(shù)的發(fā)展,這種頁(yè)面切換方式的弊端也逐漸的顯現(xiàn)出來(lái),例如每次切換頁(yè)面都需要加載資源用戶體驗(yàn)極其不好,造成服務(wù)器壓力也非常的大。為了解決多頁(yè)面應(yīng)用問(wèn)題,SPA單頁(yè)面應(yīng)用應(yīng)運(yùn)而生。SPA單頁(yè)面應(yīng)用是指只有一個(gè)html頁(yè)面,不同組件切換通過(guò)路由來(lái)實(shí)現(xiàn)。頁(yè)面在首次進(jìn)入時(shí)加載相關(guān)的資源,內(nèi)容功能都被封裝到組件中,頁(yè)面切換底層變成了組件切換,這樣就解決了多頁(yè)面應(yīng)用的很多弊端。但是單頁(yè)面應(yīng)用也不是完美無(wú)瑕的,首次進(jìn)入加載相關(guān)資源會(huì)導(dǎo)致SPA的首頁(yè)加載慢
| 分類 | 實(shí)現(xiàn)方式 | 頁(yè)面性能 | 開(kāi)發(fā)效率 | 用戶體驗(yàn) | 首屏加載 | 其他頁(yè)面加載 | SEO |
|---|---|---|---|---|---|---|---|
| 單頁(yè) | 一個(gè)html | 按需更新性能高 | 高 | 非常好 | 慢 | 快 | 差 |
| 多頁(yè) | 多個(gè)html | 整頁(yè)更新性能低 | 一般 | 一般 | 快 | 慢 | 優(yōu) |
SPA單頁(yè)面與MPA多頁(yè)面應(yīng)用方式各有優(yōu)缺點(diǎn),根據(jù)自己的項(xiàng)目需要選擇更適合自己項(xiàng)目的開(kāi)發(fā)方式(現(xiàn)在主流的是SPA應(yīng)用)。
vue-router是Vue.js官方的路由插件,它和vue.js是深度集成的,適合用于構(gòu)建單頁(yè)面應(yīng)用。
二 準(zhǔn)備工作
1 安裝
npm install vue-router@3.6.5 --save
這個(gè)地方需要注意的是你的Vue版本要與vue-router版本對(duì)應(yīng)上,否則安裝上也無(wú)法使用
vue2.x對(duì)應(yīng)的vue-router版本是 vue-router3.x
vue3.x對(duì)應(yīng)的vue-router版本是 vue-router4.x
2 引入-注冊(cè)-創(chuàng)建路由
import Router from ‘vue-router' // 引入
Vue.use(Router) // 注冊(cè)
new Router({})// 創(chuàng)建路由對(duì)于一個(gè)項(xiàng)目來(lái)說(shuō),路由與組件映射不可能只有一兩個(gè)。
當(dāng)路由非常多時(shí),將路由配置直接寫(xiě)在main.js中顯然不太好維護(hù),這里我直接建一個(gè)文件來(lái)進(jìn)行路由封裝router.js
import Vue from 'vue'
import Router from 'vue-router'
// 引入組件
import helloWord from '../views/HelloWord'
import School from '../views/School'
Vue.use(Router)
// 路由與組件綁定
export default new Router({
routes: [ {
name:'school',
path: '/school',
component: School
},{
name:'hellword',
path: '/helloWord',
component: helloWord,
}]
})3 全局引入路由
在main.js中全局引入
import router from './router'
new Vue({
el: '#app',
router, // 引入路由
render: h => h(App),
beforeCreate(){
// 全局事件總線
Vue.prototype.$bus = this
}
}).$mount('#app')以上全部的準(zhǔn)備工作已完成
若以上操作都沒(méi)有問(wèn)題,可以在控制臺(tái)打印vur-router提供的方法$ router、$ route。打印成功就可以使用路由了
$route 每個(gè)組件自己的路由信息
$router 全局都一樣,是路由的共用方法

三 路由基本方法
3.1 聲明式導(dǎo)航與編程式導(dǎo)航
聲明式路由導(dǎo)航
聲明式導(dǎo)航是通過(guò)在模板中使用特定的指令來(lái)實(shí)現(xiàn)頁(yè)面導(dǎo)航。在Vue模板中,使用< router-link>組件來(lái)創(chuàng)建導(dǎo)航鏈接,通過(guò)設(shè)置to屬性指定目標(biāo)路由的路徑或命名路由。例如:
<router-link to="/search">跳轉(zhuǎn)到搜索頁(yè)面</router-link>
優(yōu)點(diǎn):簡(jiǎn)單直觀,通過(guò)在模板中編寫(xiě)導(dǎo)航鏈接,不需要編寫(xiě)額外的Js代碼。
編程式導(dǎo)航
編程式導(dǎo)航是通過(guò)在Js代碼中使用Vue Router提供的API來(lái)實(shí)現(xiàn)頁(yè)面導(dǎo)航。通過(guò)訪問(wèn)$router對(duì)象,可以使用其提供的方法進(jìn)行頁(yè)面跳轉(zhuǎn),例如push、replace、go等。例如:
this.$router.push('/search');優(yōu)點(diǎn):可以在Js代碼中根據(jù)條件或動(dòng)態(tài)數(shù)據(jù)進(jìn)行導(dǎo)航,更加靈活和可控。
1 聲明式導(dǎo)航
router-link
配置 to 屬性指定路徑(必須) 。本質(zhì)還是a 標(biāo)簽,to 無(wú)需 #
to后面可以是path或name
// to path,默認(rèn)類似 $router.push 跳轉(zhuǎn)路由并增加一條路由歷史記錄 <router-link class="link" to="/helloWord">Helloword</router-link> // to name <router-link class="link" to="helloword">Helloword</router-link> // 替換當(dāng)前歷史記錄,跳轉(zhuǎn)到指定路由 <router-link class="link" replace to="helloword">Helloword</router-link>
2 編程式導(dǎo)航
$router.push
跳轉(zhuǎn)到指定路由,并在路由信息中增加一條歷史信息
<button class="link" @click="jump(1)">hellword</button>
jump(type) {
console.log('type', type)
if (type == 1) {
// path 方法跳轉(zhuǎn)
// this.$router.push('/helloWord')
// this.$router.push({path:'/helloWord'})
// name 方法跳轉(zhuǎn)
this.$router.push({name:'hellword'})
} else {
this.$router.push('/school')
}
}$router.replace
替換當(dāng)前歷史記錄,跳轉(zhuǎn)到指定路由
<button class="link" @click="jump(1)">hellword</button>
jump(type) {
console.log('type', type)
if (type == 1) {
this.$router.replace({name:'hellword'})
} else {
this.$router.push('/school')
}
}$router.go()
可以在瀏覽歷史中前進(jìn)和后退(正數(shù)- 前進(jìn),0 - 刷新,負(fù)數(shù) - 后退)
this.$router.go(0) // 刷新 this.$router.go(-1) // 后退1
$ router.back()
在歷史記錄中,后退到上一個(gè)頁(yè)面
$ router.forward()
在歷史記錄中,前進(jìn)到下一個(gè)頁(yè)面
完整代碼
<template>
<div id="app">
<hr />
<div class="flex">
<div class="nav">
<h1>方式一</h1>
<router-link class="link" to="/helloWord">Helloword</router-link>
<router-link class="link" to="/school">school</router-link>
<h1>方式二</h1>
<button class="link" @click="jump(1)">hellword</button>
<button class="link" @click="jump(2)">school</button>
</div>
<div class="content">
<router-view></router-view>
</div>
</div>
</div>
</template>
<script>
export default {
name: "App",
data() {
return {
};
},
mounted() {
},
methods: {
jump(type) {
console.log('type', type)
if (type == 1) {
// path 方法跳轉(zhuǎn)
// this.$router.push('/helloWord')
// this.$router.push({path:'/helloWord'})
// name 方法跳轉(zhuǎn)
// this.$router.push({name:'hellword'})
} else {
this.$router.push('/school')
}
},
},
};
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
.flex {
display: flex;
}
.nav {
width: 120px;
display: flex;
flex-direction: column;
}
.link {
margin: 3px 10px;
width: 100px;
height: 60px;
line-height: 60px;
font-size: 20px;
text-decoration: none;
border: 1px solid blue;
border-radius: 4px;
}
.content {
width: calc(100% - 100px);
height: 800px;
background-color: #eee;
}
</style>運(yùn)行效果

3.2 嵌套(多級(jí))路由
school組件下還有student路由,就可以如下方式寫(xiě)
- children子路由中的path不加/
- 子頁(yè)面訪問(wèn)路徑 /school/student
export default new Router({
routes: [ {
name:'school',
path: '/school',
component: School,
children:[{
name:'student',
path: 'student',
component: Student,
}]
},{
name:'helloword',
path: '/helloWord',
component: helloWord,
}]
})school組件
<template>
<div>
<h1>我是School</h1>
<hr>
<div @click="$router.push('/school/student')">查看學(xué)生</div>
<router-view></router-view>
</div>
</template>
3.3 路由中的參數(shù)
3.3.1 query參數(shù)
顯式傳參
1 路徑后拼接參數(shù)

2 編程式路由中傳query參數(shù)
this.$router.push({path:'/helloWord',query:{id:'01',name:'張二'}})3 注冊(cè)路由傳參
注冊(cè)路由時(shí)加參數(shù),這個(gè)基本不用,了解即可
{
name:'helloword',
path: '/helloWord',
component: helloWord,
query:{
id:'02',
name:'張三'
}
}
3.3.2 params參數(shù)
1 路徑后傳參
path: '/helloWord/:id/:name' // id、name位置對(duì)照

2 編程式路由傳參
this.$router.push({name:'helloword',params:{id:'01',name:'張二'}})特別注意:路由攜帶params參教時(shí),params不能和path一起使用會(huì)無(wú)效,params只能和name一起使用
params方法只有以上兩種方式傳遞參數(shù)
3.4 命名路由
然后我們可以使用 name 而不是 path 來(lái)傳遞 to 屬性給 < router-link>
export default new Router({
routes: [ {
name:'school',
path: '/school',
component: School,
children:[{
name:'student',
path: 'student',
component: Student,
}]
}]
})3.5 props
路由的props傳參
1 值為對(duì)象,該對(duì)象中的所有key-value都會(huì)以props的形式傳給組件
{
name:'helloword',
path: '/helloWord',
component: helloWord,
props:{id:'003',name:'林淼淼'},
}<template>
<div>
<h1>我是HelloWord</h1>
</div>
</template>
<script>
export default {
name: 'HelloWord',
props:['id','name'], // 接收傳參
mounted(){
console.log('=====id======',this.id)
console.log('=====name======',this.name)
}
}
</script>2 布爾值,若值為真,就會(huì)把該路由組件收到的所有params參數(shù),以props的形式傳給組件
{
name:'helloword',
path: '/helloWord',
component: helloWord,
props:true
}this.$router.push({name:'helloword',params:{id:'01',name:'張二'}})
<template>
<div>
<h1>我是HelloWord</h1>
</div>
</template>
<script>
export default {
name: 'HelloWord',
props:['id','name'], // 接收傳參
mounted(){
console.log('=====id======',this.id)
console.log('=====name======',this.name)
}
}
</script>3 值為函數(shù)
{
name:'helloword',
path: '/helloWord',
component: helloWord,
props($route){
// $route組件的路由信息
return {id:$route.query.id,name:$route.query.name}
},
query:{
id:'02',
name:'張三'
}
}<template>
<div>
<h1>我是HelloWord</h1>
</div>
</template>
<script>
export default {
name: 'HelloWord',
props:['id','name'], // 接收傳參
mounted(){
console.log('=====id======',this.id)
console.log('=====name======',this.name)
}
}
</script>四 路由守衛(wèi)
執(zhí)行順序

4.1 全局路由守衛(wèi)(前/后置)
routes路由中的屬性不可以隨意的自定義,而是要在meta屬性中自定義,其他地方自定義屬性都會(huì)失效
Vue.use(Router)
const routes = new Router({
routes: [ {
name:'school',
path: '/school',
component: School,
meta:{
isAuth:true,
title:'學(xué)校'
},
children:[{
name:'student',
path: 'student',
component: Student,
meta:{
isAuth:true,
title:'學(xué)生'
},
}]
},
{
name:'helloword',
path: '/helloWord',
component: helloWord,
meta:{
isAuth:true,
title:'首頁(yè)'
},
}]
})```
**前置路由守衛(wèi) beforeEach**,顧名思義在路由跳轉(zhuǎn)之前執(zhí)行,這里一般可以做頁(yè)面權(quán)限校驗(yàn)等操作
```c
// 前置路由守衛(wèi)
/**
to 目的地
from 起始地
next 放行
**/
routes.beforeEach((to,from,next)=>{
if(to.meta.isAuth){
next()
}
})前置路由守衛(wèi) beforeEach,顧名思義在路由跳轉(zhuǎn)之前執(zhí)行,這里一般可以做頁(yè)面權(quán)限校驗(yàn)等操作。
初始化時(shí)候、每次路由切換之前被調(diào)用
// 前置路由守衛(wèi)
/**
to 目的地
from 起始地
next 放行:路由跳轉(zhuǎn),next下的代碼還會(huì)繼續(xù)的執(zhí)行
**/
routes.beforeEach((to,from,next)=>{
if(to.meta.isAuth){
next()
}else{
alert('你沒(méi)有權(quán)限')
}
})后置路由守衛(wèi) afterEach,顧名思義在路由跳轉(zhuǎn)之后執(zhí)行,這里可以做title更改。
初始化時(shí)候、每次路由切換之后被調(diào)用
// 后置路由守衛(wèi)
/**
to 目的地
from 起始地
**/
routes.afterEach((to,form)=>{
document.title = to.meta.title
})4.2 獨(dú)享路由守衛(wèi)
獨(dú)享路由守衛(wèi) beforEnter,顧名思義就是某一個(gè)路由獨(dú)自享有的,只由觸發(fā)改路由時(shí)才會(huì)執(zhí)行類似路由的前置
執(zhí)行順序:全局前置 --> 獨(dú)享路由 --> 全局后置
children:[{
name:'student',
path: 'student',
component: Student,
meta:{
isAuth:true,
title:'學(xué)生'
},
// to form 用法同上
beforeEnter:(to,form,next)=>{
console.log(to,form);
next()
}
}]4.3 組件內(nèi)路由守衛(wèi)
在組件內(nèi)部設(shè)置該組件的路由守衛(wèi)
beforeRouteEnter 進(jìn)入該組件時(shí)觸發(fā)
beforeRouteLeave 離開(kāi)該組件時(shí)觸發(fā)(切換路由)
<template>
<div>
<h1>我是HelloWord</h1>
</div>
</template>
<script>
export default {
name: 'HelloWord',
props:['id','name'],
data(){
return{}
},
// 進(jìn)入該該組件時(shí)觸發(fā)
beforeRouteEnter(to,from,next){
console.log('=====enter-to======',to)
console.log('=====enter-from======',from)
next()
},
// 離開(kāi)該組件時(shí)觸發(fā)
beforeRouteLeave(to,from,next){
console.log('=====leave-to======',to)
console.log('=====leave-from======',from)
next()
}
}
</script>
五 其它
5.1 路由模式
1. hash模式
修改為hash模式
const routes = new Router({
// 模式 默認(rèn)為hash
mode: 'hash',
})#及其后面的值都是hash值

將打包后的文件發(fā)布到服務(wù)器上(如何沒(méi)有線上服務(wù)器可以啟動(dòng)本地服務(wù)發(fā)布參考:)
hash值有特殊的#標(biāo)識(shí),不會(huì)傳送給服務(wù)器端
2. history模式
修改為history模式
const routes = new Router({
// 模式
mode: 'history',
})
打包后發(fā)到本地?zé)o服務(wù)上,點(diǎn)擊可以正常的訪問(wèn),但是一旦刷新頁(yè)面就如下所示,這是因?yàn)樗⑿碌臅r(shí)候頁(yè)面會(huì)當(dāng)成資源去請(qǐng)求服務(wù)器,服務(wù)器找不到此接口就會(huì)報(bào)錯(cuò)
解決辦法:
- node中connect-history-api-fallback插件是專門解決此問(wèn)題的;
- ngix中配置分辨是否前端路由
- 通過(guò)后端去處理

3. 總結(jié)
hash模式
1.地址中永遠(yuǎn)帶著#號(hào),不美觀。
2.若以后將地址通過(guò)第三方手機(jī)app分享,若app校驗(yàn)嚴(yán)格,則地址會(huì)被標(biāo)記為不合法。
3.兼容性較好。
4.hash值不會(huì)包含在 HTTP 請(qǐng)求中,即: hash值不會(huì)帶給服務(wù)器。
history模式
1.地址干凈,美觀。
2.兼容性和hash模式相比略差。
3.應(yīng)用部署上線時(shí)需要后端人員支持,解決刷新頁(yè)面服務(wù)端404的問(wèn)題。
5.2 keep-alive緩存路由組件
原理
我們知道vue是通過(guò)vnode實(shí)現(xiàn)保存節(jié)點(diǎn)的,而keep-alive本身也是通過(guò)保存vnode來(lái)實(shí)現(xiàn)緩存的,而不是直接存儲(chǔ)DOM結(jié)構(gòu)。其實(shí)就是將需要緩存的VNode節(jié)點(diǎn)保存在this.cache中,在render時(shí),如果VNode的name符合在緩存條件(可以用include以及exclude控制),則會(huì)從this.cache中取出之前緩存的VNode實(shí)例進(jìn)行渲染。
作用
keep-alive組件是vue2.0提供的一個(gè)緩存組件,在組件切換過(guò)程中把切換出去的組件保留在內(nèi)存,不被銷毀,防止重復(fù)渲染DOM,減少加載時(shí)間及性能消耗,提高用戶體驗(yàn)性
效果
keep-alive組件,只要將子組件嵌套在這里面就可以實(shí)現(xiàn)組件的緩存,當(dāng)頁(yè)面返回時(shí)數(shù)據(jù)不會(huì)丟失,實(shí)現(xiàn)了我們常見(jiàn)的歷史頁(yè)面不刷新的效果
參數(shù)Props
include - 類型字符串、數(shù)組以及正則表達(dá)式,只有匹配的組件會(huì)被緩存
exclude - 類型字符串、數(shù)組以及正則表達(dá)式,匹配的組件不會(huì)被緩存
max - 類型字符或者數(shù)字,可以控制緩存組件的個(gè)數(shù),緩存組件的最大值
// 只緩存組件name為a或者b的組件 <keep-alive include="a,b"> <component /> </keep-alive> ? // 組件name為c的組件不緩存(可以保留它的狀態(tài)或避免重新渲染) <keep-alive exclude="c"> <component /> </keep-alive> ? // 如果同時(shí)使用include,exclude,那么exclude優(yōu)先于include, 下面的例子只緩存a組件 <keep-alive include="a,b" exclude="b"> <component /> </keep-alive> ? // 如果緩存的組件超過(guò)了max設(shè)定的值5,那么將刪除第一個(gè)緩存的組件 <keep-alive exclude="c" max="5"> <component /> </keep-alive>
用法
1、與include結(jié)合使用
// include 只緩存組件名字為home的組件,其他組件不會(huì)緩存,而exclude恰好相反 <keep-alive include="home"> <router-view /> </keep-alive>
2、結(jié)合Router中的meta屬性來(lái)控制組件緩存
{
path: '/',
name: 'home',
meta:{
keepAlive:true // 需要緩存
},
component: Home,
children: [
{
path: 'goods',
name: 'goods',
component: Goods,
meta: {
keepAlive: false // 不需要緩存
}
}
]
}<keep-alive>
<router-view v-if="$route.meta.keepAlive" />
</keep-alive>
<router-view v-if="!$route.meta.keepAlive" />緩存所有頁(yè)面:
在app.vue頁(yè)面里加keep-alive
緩存部分頁(yè)面:
1、在app.vue頁(yè)面里加keep-alive,結(jié)合keep-alive的include屬性
2、結(jié)合Router中的meta屬性,在app.vue頁(yè)面里加$route.meta.keepAlive的if判斷
小知識(shí)點(diǎn)
1、同時(shí)使用include,exclude,那么exclude優(yōu)先于include
2、緩存的組件超過(guò)了max設(shè)定的值5,那么將刪除第一個(gè)緩存的組件
3、keep-alive 不會(huì)在函數(shù)式組件中正常工作,因?yàn)樗鼈儧](méi)有緩存實(shí)例
4、keep-alive 先匹配被包含組件的 name 字段,如果 name 不可用,則匹配當(dāng)前組件 components 配置中的注冊(cè)名稱
5、只有組件被 keep-alive 包裹時(shí),這兩個(gè)生命周期函數(shù)才會(huì)被調(diào)用,如果作為正常組件使用,是不會(huì)被調(diào)用的,以及在 2.1.0
版本之后,包含在 keep-alive 中,但符合 exclude ,不會(huì)調(diào)用activated和
deactivated這兩個(gè)函數(shù)鉤子!另外,在服務(wù)端渲染時(shí),此鉤子函數(shù)也不會(huì)被調(diào)用
5.3 生命周期變化
針對(duì)路由緩存組件的多加了兩個(gè)生命周期函數(shù)
1.activated
- 在 keep-alive 組件激活時(shí)調(diào)用
- 該鉤子函數(shù)在服務(wù)器端渲染期間不被調(diào)用
- 使用 keep-alive會(huì)將數(shù)據(jù)保留在內(nèi)存中,如果要在每次進(jìn)入頁(yè)面的時(shí)候獲取最新的數(shù)據(jù),需要在 activated 階段獲取數(shù)據(jù),承擔(dān)原來(lái) created鉤子函數(shù)中獲取數(shù)據(jù)的任務(wù)。
activated(){
/**
* 緩存的組件點(diǎn)擊時(shí)調(diào)用
*/
},2.deactivated
- 在 keep-alive 組件停用時(shí)調(diào)用
- 該鉤子函數(shù)在服務(wù)器端渲染期間不被調(diào)用
- 被包含在 keep-alive中創(chuàng)建的組件,會(huì)多出兩個(gè)生命周期的鉤子: activated 與 deactivated
deactivated(){
/**
* 緩存的組件點(diǎn)擊時(shí)調(diào)用
*/
},總結(jié)
1、如何配置路由?
2、如何使用導(dǎo)航進(jìn)行路由跳轉(zhuǎn)
聲明式:router-link
編程式:this.$ router.push,this.$ router.g等
3、嵌套(多級(jí))路由如何配置與使用
- 父級(jí)路由中加children,children下就是子路由
- 子路由中的path不加/
- 子頁(yè)面訪問(wèn)路徑 /school/student
4、路由如何傳遞傳參
this.$router.push({path:‘/helloWord’,query:{id:‘01’,name:‘張二’}})
this.$router.push({name:‘helloword’,params:{id:‘01’,name:‘張二’}})
props
路徑冒號(hào)參數(shù)項(xiàng):about/:id/:name
5、路由守衛(wèi)
前置守衛(wèi) routes.beforeEach((to,from,next)=>{}) ,后置守衛(wèi) routes.afterEach((to,from,next)=>{})
獨(dú)享路由守衛(wèi)
組件內(nèi)路由守衛(wèi)
6、路由緩存
keep-alive
到此這篇關(guān)于Vue中vue-router路由使用示例詳解的文章就介紹到這了,更多相關(guān)vue-router路由使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue中this.$router.go(-1)失效(路由改變了,界面未刷新)
- vue3使用vue-router嵌套多級(jí)路由的方法
- vue中路由router配置步驟詳解
- 在vue中路由使用this.$router.go(-1)返回兩次問(wèn)題
- Vue?router?路由安裝及使用過(guò)程
- 解讀Vue-Router?使用?prams?路由傳參失效
- vue使用動(dòng)態(tài)添加路由(router.addRoutes)加載權(quán)限側(cè)邊欄的方式
- vue3中使用router路由實(shí)現(xiàn)跳轉(zhuǎn)傳參的方法
- vue3使用vue-router及路由權(quán)限攔截方式
- Vue3使用vue-router如何實(shí)現(xiàn)路由跳轉(zhuǎn)與參數(shù)獲取
相關(guān)文章
vue.draggable實(shí)現(xiàn)表格拖拽排序效果
這篇文章主要為大家詳細(xì)介紹了vue.draggable實(shí)現(xiàn)表格拖拽排序效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12
詳解vue3中watch監(jiān)聽(tīng)的幾種情況
watch是CompositionAPI的一部分,用于監(jiān)聽(tīng)響應(yīng)式數(shù)據(jù)的變化并執(zhí)行相應(yīng)的操作,本文主要介紹了詳解vue3中watch監(jiān)聽(tīng)的幾種情況,具有一定的參考價(jià)值,感興趣的可以了解一下2025-03-03
element基于el-form智能的FormSmart表單組件
本文主要介紹了element基于el-form智能的FormSmart表單組件,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04
Vue二次封裝el-select實(shí)現(xiàn)下拉滾動(dòng)加載效果(el-select無(wú)限滾動(dòng))
el-select默認(rèn)是不支持虛擬滾動(dòng)的,需要使用第三方插件來(lái)實(shí)現(xiàn)虛擬滾動(dòng)功能,下面這篇文章主要給大家介紹了關(guān)于Vue二次封裝el-select實(shí)現(xiàn)下拉滾動(dòng)加載效果的相關(guān)資料,需要的朋友可以參考下2024-04-04
vue2如何使用vue-i18n搭建多語(yǔ)言切換環(huán)境
這篇文章主要介紹了vue2-使用vue-i18n搭建多語(yǔ)言切換環(huán)境的相關(guān)知識(shí),在data(){}中獲取的變量存在更新this.$i18n.locale的值時(shí)無(wú)法自動(dòng)切換的問(wèn)題,需要刷新頁(yè)面才能切換語(yǔ)言,感興趣的朋友一起看看吧2023-12-12
Vue.js列表渲染綁定jQuery插件的正確姿勢(shì)
這篇文章主要為大家詳細(xì)介紹了Vue.js列表渲染綁定jQuery插件的正確姿勢(shì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
一文詳解Vue3組件通信輕松玩轉(zhuǎn)復(fù)雜數(shù)據(jù)流
在大型Vue項(xiàng)目中,組件通信如同神經(jīng)網(wǎng)絡(luò)般貫穿整個(gè)應(yīng)用,這篇文章將為大家詳細(xì)介紹一下Vue3中的組件通信方式,有需要的小伙伴可以了解下2025-02-02
Antd的Table組件嵌套Table以及選擇框聯(lián)動(dòng)操作
這篇文章主要介紹了Antd的Table組件嵌套Table以及選擇框聯(lián)動(dòng)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10
vuejs數(shù)據(jù)超出單行顯示更多,點(diǎn)擊展開(kāi)剩余數(shù)據(jù)實(shí)例
這篇文章主要介紹了vuejs數(shù)據(jù)超出單行顯示更多,點(diǎn)擊展開(kāi)剩余數(shù)據(jù),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05
vue使用Google Recaptcha驗(yàn)證的實(shí)現(xiàn)示例
我們最近的項(xiàng)目中需要使用谷歌機(jī)器人驗(yàn)證,所以就動(dòng)手實(shí)現(xiàn)一下,本文就來(lái)詳細(xì)的介紹一下vue Google Recaptcha驗(yàn)證,感興趣的可以了解一下2021-08-08

