码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-05-14 19:50:27      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:community   vue   stl   hot   index   indexof   otl   err   com   

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
                    }
                })
            }
        }
    }

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

标签:community   vue   stl   hot   index   indexof   otl   err   com   

原文地址:https://www.cnblogs.com/meijiemu/p/9037561.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!