Przeglądaj źródła

ensure $scopedSlots is always an object (close #4301)

Evan You 9 lat temu
rodzic
commit
aa5f5d1198
2 zmienionych plików z 4 dodań i 4 usunięć
  1. 1 1
      flow/component.js
  2. 3 3
      src/core/instance/render.js

+ 1 - 1
flow/component.js

@@ -25,7 +25,7 @@ declare interface Component {
   $children: Array<Component>;
   $refs: { [key: string]: Component | Element | Array<Component | Element> | void };
   $slots: { [key: string]: Array<VNode> };
-  $scopedSlots: ?{ [key: string]: () => VNodeChildren };
+  $scopedSlots: { [key: string]: () => VNodeChildren };
   $vnode: VNode;
   $isServer: boolean;
 

+ 3 - 3
src/core/instance/render.js

@@ -16,7 +16,7 @@ export function initRender (vm: Component) {
   vm._staticTrees = null
   vm._renderContext = vm.$options._parentVnode && vm.$options._parentVnode.context
   vm.$slots = resolveSlots(vm.$options._renderChildren, vm._renderContext)
-  vm.$scopedSlots = null
+  vm.$scopedSlots = {}
   // bind the public createElement fn to this instance
   // so that we get proper render context inside it.
   vm.$createElement = bind(createElement, vm)
@@ -45,7 +45,7 @@ export function renderMixin (Vue: Class<Component>) {
       }
     }
 
-    if (_parentVnode) {
+    if (_parentVnode && _parentVnode.data.scopedSlots) {
       vm.$scopedSlots = _parentVnode.data.scopedSlots
     }
 
@@ -191,7 +191,7 @@ export function renderMixin (Vue: Class<Component>) {
     fallback: ?Array<VNode>,
     props: ?Object
   ): ?Array<VNode> {
-    const scopedSlotFn = this.$scopedSlots && this.$scopedSlots[name]
+    const scopedSlotFn = this.$scopedSlots[name]
     if (scopedSlotFn) { // scoped slot
       return scopedSlotFn(props || {}) || fallback
     } else {