Explorar o código

expose component placeholder node in render fns as this.$vnode

Evan You %!s(int64=10) %!d(string=hai) anos
pai
achega
7630622689
Modificáronse 2 ficheiros con 6 adicións e 2 borrados
  1. 1 0
      flow/component.js
  2. 5 2
      src/core/instance/render.js

+ 1 - 0
flow/component.js

@@ -26,6 +26,7 @@ declare interface Component {
   $children: Array<Component>;
   $refs: { [key: string]: Component | Element | Array<Component | Element> | void };
   $slots: { [key: string]: Array<VNode> };
+  $vnode: VNode;
   $isServer: boolean;
 
   // public methods

+ 5 - 2
src/core/instance/render.js

@@ -17,7 +17,8 @@ export const renderState: {
 }
 
 export function initRender (vm: Component) {
-  vm._vnode = null
+  vm.$vnode = null // the placeholder node in parent tree
+  vm._vnode = null // the root of the child tree
   vm._staticTrees = null
   vm.$slots = {}
   // bind the public createElement fn to this instance
@@ -50,7 +51,9 @@ export function renderMixin (Vue: Class<Component>) {
     if (staticRenderFns && !this._staticTrees) {
       this._staticTrees = []
     }
-
+    // set parent vnode. this allows render functions to have access
+    // to the data on the placeholder node.
+    this.$vnode = _parentVnode
     // resolve slots. becaues slots are rendered in parent scope,
     // we set the activeInstance to parent.
     if (_renderChildren) {