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
                    }
                })
            }
        }
    }
posted @ 2018-05-14 17:59  挨踢人啊  阅读(1654)  评论(0编辑  收藏  举报