beforeRouteEnter、beforeRouteUpdate、beforeRouteLeave

    beforeRouteEnter (to, from, next) {
        alert('beforeRouteEnterfrom='+from.name)
        // 在渲染該組件的對應路由被 confirm 前調用
        // 不!能!獲取組件實例 `this`
        // 因爲當守衛執行前,組件實例還沒被創建
        next();
    },
    beforeRouteUpdate (to, from, next) {
        alert('beforeRouteUpdatefrom='+from.name)
        // 在當前路由改變,但是該組件被複用時調用
        // 舉例來說,對於一個帶有動態參數的路徑 /foo/:id,在 /foo/1 和 /foo/2 之間跳轉的時候,
        // 由於會渲染同樣的 Foo 組件,因此組件實例會被複用。而這個鉤子就會在這個情況下被調用。
        // 可以訪問組件實例 `this`
        next();
    },
    beforeRouteLeave (to, from, next) {
        alert('beforeRouteLeavefrom='+from.name)
        // 導航離開該組件的對應路由時調用
        // 可以訪問組件實例 `this`
        next();
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章