vue-router變化,頁面不刷新

現象

在頁面上操做後,地址的 query execute_status 須要變化,在代碼中使用 this.$router.push() 以後,頁面沒有刷新,腳本沒有執行。
40B4296D-4B0F-427B-A432-24B172CB130A.pnghtml

緣由

兩個地址使用的是同一個組件,比起銷燬原組件後建立新組件,複用組件的效率更高,因此頁面上沒有更新。vue

解決

第一種方案

監聽路由$route變化react

watch: {
    '$route' (to, from) {
      // 對路由變化做出響應...
    }
  }

第二種方案

利用路由的鉤子函數:beforeRouteUpdateide

beforeRouteUpdate (to, from, next) {
    // react to route changes...
    // don't forget to call next()
  }

詳見官網:https://router.vuejs.org/zh/guide/essentials/dynamic-matching.html#%E5%93%8D%E5%BA%94%E8%B7%AF%E7%94%B1%E5%8F%82%E6%95%B0%E7%9A%84%E5%8F%98%E5%8C%96函數

相關文章
相關標籤/搜索