首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

(三)computed和watch区别

methods、computed、watch:他们三者的区别 他们三者都可以完成一些相同的功能 methods可以把他当作原生的js方法或者是函数来使用,可以把watch 里面的代码写成方法放到methodsd...当中通过this.xxxopen in new window 的方式去调用,这样可以减少watch带代码,更加方便维护 computed他是有缓存的,如果依赖的tata数据不改变他就会一直使用缓存,computed...使用的数据需要return出去才可以使用,在页面上可以直接使用computed 里面的属性 watch 可以用来做一些比较费时的操作,比如网络请求等等之类的,watch没有返回值,他是去修改data里面的数据...的两种写法 // 一般需求都是使用简写方式,方法写法,就是使用 get 只读取数据 computed: { 方法名直接在模板页面使用() { return 业务逻辑 }...,何时又使用watch呢 computed:依赖的数据发生改变才会触发回调 watch:监听的变量发生改变就会触发回调 根据以上说明自行在合适的地方选择使用

27250

【Vue原理】Computed - 源码版

2、computed 怎么计算 3、computed 的缓存是怎么做的 4、computed 什么时候初始化 5、computed 是怎么可以直接使用实例访问到的 问题不会按顺序解析,因为这些问题会互相关联...配发 watcher 2、defineComputed 处理 3、收集所有 computed 的 watcher 好的,这三件事,一件一件说哈 1、每个 computed 配发 watcher computed...2、computed 被读取,createComputedGetter 包装的函数触发,第一次会进行计算 computed-watcher.evaluted 被调用,进而 computed-watcher.get...3、computed 计算会读取 data,此时 data 就收集到 computed-watcher 同时 computed-watcher 也会保存到 data 的依赖收集器 dep(用于下一步)。...,computed 先更新,页面再更新,所以,页面才能读取到最新的 computed 值 [公众号] [公众号] 3、收集所有 computed 的 watcher 从源码中,你可以看出为每个computed

1K50
领券