[web教学] Vue2 watch监听props的值

[复制链接]
查看828 | 回复0 | 2023-8-23 11:59:03 | 显示全部楼层 |阅读模式 来自 中国北京
再次碰到监听子组件收到父组件传过来的值,如果这个值变革,页面中的值发现是不会跟着同步变革的。所以监听props中的值,不停监听。

 
代码:
  1. props: {
  2.     start:{
  3.        type: String,
  4.     },
  5.     end:{
  6.        type: String,
  7.     }
  8.   },
复制代码
 
  1.     computed:{
  2.      myStart:function(){
  3.       return this.start
  4.      },
  5.           myEnd:function(){
  6.       return this.end
  7.      }
  8.     },
  9.       watch: {
  10.     myStart:function(newVal){
  11.       if(newVal){
  12.         this.startTime=newVal
  13.       }
  14.       },
  15.     myEnd:function(newVal){
  16.       if(newVal){
  17.         this.endTime=newVal
  18.       }
  19.       },
  20.   },
复制代码


来源:https://blog.csdn.net/qq_46617584/article/details/129725226
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则