Vue.js 提供了一个方法 watch,它用于观察Vue实例上的数据变动。对应一个对象,键是观察表达式,值是对应回调。值也可以是方法名,或者是对象,包含选项。

例如,同一个组件切换时,不会触发生命周期函数,我们可以用watch监视$route,实现生命周期函数可实现的操作。

    watch: {
        $route: {
            handler: function(val, oldVal) {
                this.selectSelfCreate = this.$route.query.selectSelfCreate;
                //调用接口获取数据
            },
            deep: true
        }

 

posted on 2018-06-21 12:59  chester·chen  阅读(156)  评论(0编辑  收藏  举报