vue提供了一种通用的方式来观察和响应vue实例上的数据变动:侦听属性。当有一些数据需要随着其他数据变动而变动时,(如果我们之前使用过angular js)----很容易滥用watch,其实可能更好的方法是计算属性computed
如下使用watch 编写的代码,看着冗余,复杂:

使用计算属性computed:

页面呈现效果:

总结:哪个简单,方便,一目了然
vue提供了一种通用的方式来观察和响应vue实例上的数据变动:侦听属性。当有一些数据需要随着其他数据变动而变动时,(如果我们之前使用过angular js)----很容易滥用watch,其实可能更好的方法是计算属性computed
如下使用watch 编写的代码,看着冗余,复杂:
使用计算属性computed:
页面呈现效果:
总结:哪个简单,方便,一目了然
本文标题:vue学习之watch与computed的比较
本文链接:https://www.haomeiwen.com/subject/txhubctx.html
网友评论