vue 點選當前路由重新載入該路由

2022-06-25 15:42:13 字數 1596 閱讀 7298

需求:點選當前路由實現資料請求頁面重新整理 -- router.push(當前路由)並不會執行

重新整理頁面

1、window.reload()

2、this.$router.go(0)

3、v-if ,控制router-view的顯示或隱藏,從而控制頁面的再次載入,

如果是選單,感覺控制選單顯隱不太好

4、借助第三方元件實現兩次路由跳轉

思路:   

1)判斷是否點選的當前路由,如果是,則跳轉到空白的第三方元件,並傳遞當前路由。

2)在空白元件中 created 的生命週期中接受引數,並執行頁面跳轉,此時頁面不會顯示任何內容就開始進行跳轉,所以速度的問題不用擔心,視覺上的效果就是點選當前路由後,頁面重新整理請求資料。實際路由已經跳轉了兩次。

//選單點選的**

handleselect(key, keypath) )}}

// 空白模板 

console.log('設定或獲取物件指定的檔名或路徑               -- window.location.pathname---',   window.location.pathname);

console.log('設定或獲取整個 url 為字串 -- window.location.href--------', window.location.href);

console.log('設定或獲取location或url的hostname和port號碼 -- window.location.host-------', window.location.host);

console.log('設定或獲取與 url 關聯的埠號碼 -- window.location.port--------', window.location.port);

console.log('設定或獲取 url 的協議部分 -- window.location.protocol---', window.location.protocol);

console.log('設定或獲取 href 屬性中在井號「#」後面的分段 -- window.location.hash-------', window.location.hash);

console.log('設定或獲取 href 屬性中跟在問號後面的部分 -- window.location.search------', window.location.search);

console.log('獲取當前網頁的網域名稱 -- document.domain-------------', document.domain);

console.log('獲取當前網頁的路由 --this.$route.path-------------', this.$route.path);

Vue重新整理當前路由

開發專案的時候突然接到了這個需求,實驗過後,解決方法也蠻多種,下面就講下常規的幾種方案 通過改變router view中的key值,來達到重新整理元件的目的 router view this.activedate new date 通過 nexttick 協助實現。先把 移除,移除後再重新新增,達到...

Vue重新整理 過載當前路由獲取資料

vue如何重新整理或過載當前路由來更新資料?vue如何監聽同一路由載入事件?方案 可以利用路由的quey引數,使用watch進行檢測router的變化實現監聽。下面是乙個實踐示例 vue重新整理資料當然簡單,直接呼叫合資料的方法就行。但是,往往業務需求的不同,實現流程或思路也會不同。下面有乙個業務需...

vue 路由元件不重新載入

doctype html html head meta charset utf 8 title vue 測試例項 菜鳥教程 runoob.com title script src script script src script head body div id h1h1 p router link...