亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue如何實(shí)現(xiàn)動(dòng)態(tài)改變地址欄的參數(shù)值

 更新時(shí)間:2022年07月29日 15:46:43   作者:whylost迷心  
這篇文章主要介紹了vue如何實(shí)現(xiàn)動(dòng)態(tài)改變地址欄的參數(shù)值,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

動(dòng)態(tài)改變地址欄的參數(shù)值

點(diǎn)擊切換Tab,通過(guò)watch監(jiān)聽(tīng),在地址欄修改對(duì)應(yīng)得active參數(shù),這樣刷新后還能保持最后瀏覽的tab

watch: {
? ? active (newValue) {
? ? ? let query = this.$router.history.current.query;
? ? ? let path = this.$router.history.current.path;
? ? ? //對(duì)象的拷貝
? ? ? let newQuery = JSON.parse(JSON.stringify(query));
? ? ? // 地址欄的參數(shù)值賦值
? ? ? newQuery.active = newValue;
? ? ? this.$router.push({ path, query: newQuery });
? ? }
? }

監(jiān)聽(tīng)url地址欄參數(shù)變化

問(wèn)題:

在開(kāi)發(fā)過(guò)程中我們有可能會(huì)遇到一個(gè)問(wèn)題,就是在一個(gè)vue項(xiàng)目中引入了一個(gè)組件,點(diǎn)擊這個(gè)組件跳轉(zhuǎn)的還是當(dāng)前的頁(yè)面,只是傳遞的參數(shù)發(fā)生了變化,這個(gè)時(shí)候我們傳遞的參數(shù)就不能正常的賦值了,這是因?yàn)轫?yè)面沒(méi)有重新加載,所以我們就要監(jiān)聽(tīng)地址欄的參數(shù)變化了。

1.傳遞參數(shù)

?? ?this.$router.push({
?? ? ? ?path: url,//路由地址
?? ? ? ?query:{//參數(shù)
?? ? ? ? ? ?type: 1
?? ? ? ?}
?? ?});

2.監(jiān)聽(tīng)參數(shù)變化

?? ?watch: {
?? ? ? ?//監(jiān)聽(tīng)路由地址的改變
?? ? ? ?$route:{
?? ? ? ? ? ?immediate:true,
?? ? ? ? ? ?handler(){
?? ? ? ? ? ? ? ?if(this.$route.query.type){//需要監(jiān)聽(tīng)的參數(shù)
?? ? ? ? ? ? ? ? ? ?this.type = this.$route.query.type
?? ? ? ? ? ? ? ?}
?? ? ? ? ? ?}
?? ? ? ?}
?? ?}

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。 

相關(guān)文章

最新評(píng)論