markStaticRoots 函数中标记 staticInFor ,是用来干嘛呢。
来源:7-2 optimize(下)

Arey_jy
2019-04-28
function markStaticRoots (node: ASTNode, isInFor: boolean) {
if (node.type === 1) {
if (node.static || node.once) {
node.staticInFor = isInFor
}
// For a node to qualify as a static root, it should have children that
// are not just static text. Otherwise the cost of hoisting out will
// outweigh the benefits and it's better off to just always render it fresh.
if (node.static && node.children.length && !(
node.children.length === 1 &&
node.children[0].type === 3
)) {
node.staticRoot = true
return
} else {
node.staticRoot = false
}
if (node.children) {
for (let i = 0, l = node.children.length; i < l; i++) {
markStaticRoots(node.children[i], isInFor || !!node.for)
}
}
if (node.ifConditions) {
for (let i = 1, l = node.ifConditions.length; i < l; i++) {
markStaticRoots(node.ifConditions[i].block, isInFor)
}
}
}
}
看单词应该是标记带有v-for的元素的静态节点吗?还有就是为什么要if (node.static || node.once) 中对once 也要标记。
写回答
1回答
-
ustbhuangyi
2019-04-28
是指在 v-for 内部的静态节点。
这个是为了运行时渲染静态树用的00
相似问题