javascript - How does vue-router distinguish between to and from in watch?
滿天的星座
滿天的星座 2017-05-19 10:46:34
0
2
574
created () {
    this.getData()
},
watch: {
    $route (to, from) {
        // 执行ajax请求,但只希望在进入时请求,离开时不希望进行请求。
        this.getData()
    }
}

The current situation is that the router makes requests when entering or leaving. How to solve unnecessary requests?

Thanks you in advance.

滿天的星座
滿天的星座

reply all(2)
滿天的星座

beforeRouteEnter is better?

曾经蜡笔没有小新

Use routing hook function

beforeEnter

or component hook function

beforeRouteEnter
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template