vue教程-methods 和 计算属性(computed)的区别

区别

  1. 调用 methods 方法时,需要加 (),调用 computed 方法时,不能加 ()

  2. 调用 methods 方法时,显示返回数据。每次调用,都会执行方法

  3. 调用 computed 时,显示返回数据。第一次调用,执行结果就放到缓存里面。以后再调用 computed 方法的时候,当方法依赖的 数据没有发生改变 时,不会执行 computed 方法,直接从缓存中返回数据。当方法依赖的 数据发生改变 时,会执行 computed 方法,返回最新的执行结果。


原文出处:/show_1IX36bH6Bvum.html