vue.js 源代码学习笔记 ----- keep-alives
2024-08-29 15:47:00
/* @flow */ import { callHook } from 'core/instance/lifecycle'
import { getFirstComponentChild } from 'core/vdom/helpers/index' const patternTypes = [String, RegExp] function matches (pattern: string | RegExp, name: string): boolean {
if (typeof pattern === 'string') {
return pattern.split(',').indexOf(name) > -1
} else {
return pattern.test(name)
}
} export default {
name: 'keep-alive',
abstract: true,
props: {
include: patternTypes,
exclude: patternTypes
},
created () {
this.cache = Object.create(null)
},
render () {
const vnode: VNode = getFirstComponentChild(this.$slots.default)
if (vnode && vnode.componentOptions) {
const opts: VNodeComponentOptions = vnode.componentOptions
// check pattern
const name = opts.Ctor.options.name || opts.tag
if (name && (
(this.include && !matches(this.include, name)) ||
(this.exclude && matches(this.exclude, name))
)) {
return vnode
}
const key = vnode.key == null
// same constructor may get registered as different local components
// so cid alone is not enough (#3269)
? opts.Ctor.cid + (opts.tag ? `::${opts.tag}` : '')
: vnode.key
if (this.cache[key]) {
vnode.child = this.cache[key].child
} else {
this.cache[key] = vnode
}
vnode.data.keepAlive = true
}
return vnode
},
destroyed () {
for (const key in this.cache) {
const vnode = this.cache[key]
callHook(vnode.child, 'deactivated')
vnode.child.$destroy()
}
}
}
最新文章
- doT.js学习
- 二次、三次贝塞尔曲线demo(演示+获取坐标点)
- hadoop源码编译——2.5.0版本
- mysql的卸载方法
- ae 打开地图文档
- [ionic开源项目教程] - 手把手教你使用移动跨平台开发框架Ionic开发一个新闻阅读APP
- 51nod 博弈论水题
- 奥运会订票系统c语言代写源码下载
- Hadoop初步认识
- C语言位运算符:与、或、异或、取反,左移和右移
- hasLayout与Block formatting contexts的学习(下)
- 轮值CEO胡厚崑:到2025年所有的企业都将用到云(云的2.0时代,会有几千朵云几万朵云升起来,这将产生不同的技术模式、商业模式、思维模式)
- activity的生命周期详解
- Linux系统常见调用及其分类
- Java 多线程系列 CountDownLatch
- Ubuntu上部署tomcat后无法访问8080端口问题
- [转帖]2015年时微软Win3.1崩溃迫使巴黎奥利机场短暂关闭
- 谁在用 Hadoop
- nodejs——发送邮件(带附件)
- SpringCloud之Eureka 服务注册和服务发现基础篇2