升级路径

    运行 迁移路径 找到 activate 钩子的示例。

    canActivate 替换

    使用beforeEnter 在路由中作为替代。

    升级路径

    运行 迁移路径 找到 canActivate 钩子的示例。

    升级路径

    运行 迁移路径 找到 deactivate 钩子的示例。

    canDeactivate 替换

    在组件中使用beforeRouteLeave 作为替代。

    升级路径

    运行 迁移路径 找到 canDeactivate 钩子的示例。

    升级路径

    运行 迁移助手 找到 canReuse: false 选项的示例。

    data 替换

    $route属性是响应式的,所以你可以就使用一个 watcher 去响应路由的改变,就像这样:

    升级路径

    运行 找到 data 钩子的示例。

    1. return {
    2. posts: [],
    3. isLoading: false,
    4. fetchError: null
    5. }
    6. },
    7. watch: {
    8. '$route': function () {
    9. var self = this
    10. self.isLoading = true
    11. self.fetchData().then(function () {
    12. self.isLoading = false
    13. },
    14. methods: {
    15. fetchData: function () {
    16. var self = this
    17. return axios.get('/api/posts')
    18. .then(function (response) {
    19. self.posts = response.data.posts
    20. })
    21. .catch(function (error) {
    22. self.fetchError = error
    23. })
    24. }