Vue beforeUpdate 生命周期钩子
实例
使用 beforeUpdate 生命周期钩子来计算触发更新的次数。
export default {data() {return {sliderVal: 50,renderCount: 0}},beforeUpdate() {this.renderCount++;}}
定义与用法
beforeUpdate 生命周期钩子发生在 Vue 的反应系统检测到需要新渲染的更改之后,但在该渲染发生之前。
为了避免无限循环,我们应该始终考虑使用 beforeUpdate 生命周期钩子,而不是 updated 的生命周期钩子。
关联页面
Vue 教程: Vue 生命周期钩子
Vue 教程: mounted 钩子
Vue 教程: updated 钩子
Vue 参考引用: Vue updated 生命周期