vue使用watch 观察路由变化,重新获取内容

时间:2022-06-02
本文章向大家介绍vue使用watch 观察路由变化,重新获取内容,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
watch: {
        $route(to) {
            console.log(to)
            if (to.path.indexOf('index') != -1) {
                //路由变化后重新获取帖子列表
                this.$http.get('/api/communityList').then((res) => {
                    if (res.data.errCode === 0) {
                        let getRes = res.data.data.hotList
                        this.postList = getRes
                    }
                })
            }
        }
    }