props里的值在mounted里拿不到的问题

有时候父组件通过props把值传给子组件,

子组件在mounted里用props传过来值作为参数去发送请求,有时会拿不到值的情况

利用监听可以解决这个问题

 原:

父组件

 <CalendarView :staffId="staffId"/>

子组件

props: ['staffId'],
 mounted() {
        this.getScheduleInfo(staffId)
}

现:

 watch:{
        staffId: function (val){
                 this.getScheduleInfo(val)
        }
}

 

posted @ 2022-09-16 17:26  幻影之舞  阅读(603)  评论(0)    收藏  举报