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
                    }
                })
            }
        }
    }
原文地址:https://www.cnblogs.com/aacoutlook/p/9037422.html