vue 动态监听父级传过来的数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34117170/article/details/81387753

vue 动态监听父级传过来的数据,如果父级传过来的数据有变,就调用方法(你想调用的),$nextTick要加上不然会因没加载完毕而报错,还有一点handler这里使用普通函数就行,箭头函数会导致this不知道指向谁

  props:{
         cId:Number
        },
        watch:{
            cId:{  
                handler:function(val,oldval){ 
                    if(val!=oldval){
                        this.$nextTick(()=>{
                            this.getProductList()
                        })
                    }
                },  
                immediate:true,//关键
                deep:true
            },
        },

猜你喜欢

转载自blog.csdn.net/qq_34117170/article/details/81387753