In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
这篇文章主要为大家展示了"vue中watch监听方法有哪些",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"vue中watch监听方法有哪些"这篇文章吧。
1.vue中的watch作用就如其命名就是监听的作用
比如有个对象:
watchData: { name: '', age: '',}2.监听这个对象的属性
watchData: { handler: function() { console.log(); }, deep: true}
监听对象可以用deep,深度监测,不然监测不到对象的变化
3.监听这个对象的属性
方式一:
watch: { 'watchData.name'(newValue, oldValue) { console.log(newValue); }}
方式二:
watch: { 'watchData.name': { handler: function() { console.log(); } }},
为什么要监听对象的属性,监听对象的话,一旦对象内部的任何数据变化,都会导致watch重新执行,这样的话可能不是你想要的监听某一个属性变化才执行watch,或者是一旦说对象内部任何一个属性变化就让其watch执行,也会对性能有一定性的损耗,所以我们用这种监听对象单个属性的方式来处理,给要监听的"对象.属性,用引号包裹起来"
4.监听这个对象的属性
computed: { getName() { return this.watchData.name }},watch: { getName(newValue, oldValue) { console.log(newValue); }},
这种方式其实和第二种是一样的,区别就是用到了computed,然后再监听方法getName,实际上方法getName返回的就是watchData对象中的name属性
以上是"vue中watch监听方法有哪些"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.