在 About 刷新一次页面
还有一些用在我也不太常用的 lifecycle 这次就一起 Demo 一下顺序
从 About 切到 Home
这是一个原本用在 dynamic component 的 lifecycle,为了在常切换 component 的情境之下,不要重复的销毁又重新建立 component。
因为有它保持让 component 一直存在,所以,不再触发 created 和 destoryed 那麽在上面的初始与释放资源的行为怎麽办?就不会有任何机会再触发了?
<keep-alive>
<component :is="view"></component>
</keep-alive>
在我的例子上,要将 keep-alive 加在 router-view 上面
router-view, API Reference | Vue Router
<keep-alive>
<router-view />
</keep-alive>
加上两个 life cycle
{
// ...
destroyed() {
console.warn('[component About] destroyed', this.user)
},
activated() {
console.warn('[component About] activated', this.user)
},
deactivated() {
console.warn('[component About] deactivated', this.user)
}
}
刷新页面,进入 Home
切换到 About
切回 Home
可以发现 About 的 beforeRouteLeave 之後就看不到 Home 的 lifecycle 了。
created、mounted 和 destoryed 都没有出现了
切回 About
vm.$nextTick( [callback] ), API — Vue.js
用「等 DOM 更新好之後,再执行的时候」通常在这个时候如果有一些 jQuery 套件会需要执行 document.querySelector
就要在这个时候执行。
通常会在 mounted 时才注册 nextTick 的 callback
export default {
// ...
mounted() {
this.$nextTick(function () {
// DOM is now updated
// `this` is bound to the current instance
this.doSomething()
}
}
}
通常会因为简单的 DOM 结构渲染速度很快,加上非同步的关系,所以很少使用这个 hook。
<<: 【第二一天 - Flutter Blue 蓝芽文件说明】
通过审核(查看日志)来跟踪“谁做了什麽”来确定或确定责任制。记帐记录“已完成的工作”,而身份验证则标...
今天我们来看一下 powershell 中的另一种逻辑判断 switch. switch 语法: s...
前端在走,jS要懂。 所以今天来复习点基础的jS概念,首先知道HTML里的每段开始跟结尾的标签都是元...
前言 由於JavaScript是一个单线程的程序语言,这意味着JavaScript一次只能做一件事,...
MAC OS 不能发讯息怎麽办!? 自己写! 发现大部分 Telegram 的 Actions MA...