1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | export function renderStatic (
|
7 | index: number,
|
8 | isInFor: boolean
|
9 | ): VNode | Array<VNode> {
|
10 | const cached = this._staticTrees || (this._staticTrees = [])
|
11 | let tree = cached[index]
|
12 |
|
13 |
|
14 | if (tree && !isInFor) {
|
15 | return tree
|
16 | }
|
17 |
|
18 | tree = cached[index] = this.$options.staticRenderFns[index].call(
|
19 | this._renderProxy,
|
20 | null,
|
21 | this
|
22 | )
|
23 | markStatic(tree, `__static__${index}`, false)
|
24 | return tree
|
25 | }
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | export function markOnce (
|
32 | tree: VNode | Array<VNode>,
|
33 | index: number,
|
34 | key: string
|
35 | ) {
|
36 | markStatic(tree, `__once__${index}${key ? `_${key}` : ``}`, true)
|
37 | return tree
|
38 | }
|
39 |
|
40 | function markStatic (
|
41 | tree: VNode | Array<VNode>,
|
42 | key: string,
|
43 | isOnce: boolean
|
44 | ) {
|
45 | if (Array.isArray(tree)) {
|
46 | for (let i = 0; i < tree.length; i++) {
|
47 | if (tree[i] && typeof tree[i] !== 'string') {
|
48 | markStaticNode(tree[i], `${key}_${i}`, isOnce)
|
49 | }
|
50 | }
|
51 | } else {
|
52 | markStaticNode(tree, key, isOnce)
|
53 | }
|
54 | }
|
55 |
|
56 | function markStaticNode (node, key, isOnce) {
|
57 | node.isStatic = true
|
58 | node.key = key
|
59 | node.isOnce = isOnce
|
60 | }
|