From d1fc82dbba86a91704269e62699f63d645dd8baf Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 15 Apr 2016 19:36:58 -0400 Subject: [PATCH] fix parent data merge --- src/runtime/instance/render.js | 35 ++++++++++++++++++++-------------- src/runtime/instance/state.js | 1 + 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/runtime/instance/render.js b/src/runtime/instance/render.js index 4fd5f01a4..de6361dd7 100644 --- a/src/runtime/instance/render.js +++ b/src/runtime/instance/render.js @@ -1,5 +1,5 @@ import Watcher from '../observer/watcher' -import { query, resolveAsset, hasOwn } from '../util/index' +import { extend, query, resolveAsset, hasOwn } from '../util/index' import { createElement, patch, updateListeners } from '../vdom/index' import { callHook } from './lifecycle' import { getPropValue } from './state' @@ -40,10 +40,10 @@ function resolveSlots (vm, children) { } } -function mergeParentAttrs (vm, data, parentData) { +function mergeParentData (vm, data, parentData) { const props = vm.$options.props if (parentData.attrs) { - const attrs = data.attrs || (data.attrs = []) + const attrs = data.attrs || (data.attrs = {}) for (let key in parentData.attrs) { if (!hasOwn(props, key)) { attrs[key] = parentData.attrs[key] @@ -51,17 +51,27 @@ function mergeParentAttrs (vm, data, parentData) { } } if (parentData.props) { - + const props = data.props || (data.props = {}) + for (let key in parentData.props) { + if (!hasOwn(props, key)) { + props[key] = parentData.props[key] + } + } + } + if (parentData.staticClass) { + data.staticClass = data.staticClass + ? data.staticClass + ' ' + parentData.staticClass + : parentData.staticClass + } + if (parentData.class) { + extend((data.class || (data.class = {})), parentData.class) + } + if (parentData.style) { + extend((data.style || (data.style = {})), parentData.style) } -} - -function mergeParentDirectives (vm, data, parentData) { if (parentData.directives) { data.directives = parentData.directives.conact(data.directives || []) } -} - -function updateParentCallbacks (vm, data, parentData) { if (parentData.on) { updateListeners(parentData.on, data.on || {}, (event, handler) => { vm.$on(event, handler) @@ -140,10 +150,7 @@ export function renderMixin (Vue) { vnode.key = _renderKey // update parent data if (_renderData) { - const data = vnode.data - mergeParentAttrs(this, data, _renderData) - mergeParentDirectives(this, data, _renderData) - updateParentCallbacks(this, data, _renderData) + mergeParentData(this, vnode.data, _renderData) } return vnode } diff --git a/src/runtime/instance/state.js b/src/runtime/instance/state.js index efd90cba9..9ac1a0943 100644 --- a/src/runtime/instance/state.js +++ b/src/runtime/instance/state.js @@ -36,6 +36,7 @@ function initProps (vm) { } export function getPropValue (data, key) { + if (!data) return const altKey = hyphenate(key) return getPropValueFromHash(data.attrs, key, altKey) || getPropValueFromHash(data.props, key, altKey)