Skip to content

Commit d1fc82d

Browse files
committed
fix parent data merge
1 parent 11a4add commit d1fc82d

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

Diff for: src/runtime/instance/render.js

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Watcher from '../observer/watcher'
2-
import { query, resolveAsset, hasOwn } from '../util/index'
2+
import { extend, query, resolveAsset, hasOwn } from '../util/index'
33
import { createElement, patch, updateListeners } from '../vdom/index'
44
import { callHook } from './lifecycle'
55
import { getPropValue } from './state'
@@ -40,28 +40,38 @@ function resolveSlots (vm, children) {
4040
}
4141
}
4242

43-
function mergeParentAttrs (vm, data, parentData) {
43+
function mergeParentData (vm, data, parentData) {
4444
const props = vm.$options.props
4545
if (parentData.attrs) {
46-
const attrs = data.attrs || (data.attrs = [])
46+
const attrs = data.attrs || (data.attrs = {})
4747
for (let key in parentData.attrs) {
4848
if (!hasOwn(props, key)) {
4949
attrs[key] = parentData.attrs[key]
5050
}
5151
}
5252
}
5353
if (parentData.props) {
54-
54+
const props = data.props || (data.props = {})
55+
for (let key in parentData.props) {
56+
if (!hasOwn(props, key)) {
57+
props[key] = parentData.props[key]
58+
}
59+
}
60+
}
61+
if (parentData.staticClass) {
62+
data.staticClass = data.staticClass
63+
? data.staticClass + ' ' + parentData.staticClass
64+
: parentData.staticClass
65+
}
66+
if (parentData.class) {
67+
extend((data.class || (data.class = {})), parentData.class)
68+
}
69+
if (parentData.style) {
70+
extend((data.style || (data.style = {})), parentData.style)
5571
}
56-
}
57-
58-
function mergeParentDirectives (vm, data, parentData) {
5972
if (parentData.directives) {
6073
data.directives = parentData.directives.conact(data.directives || [])
6174
}
62-
}
63-
64-
function updateParentCallbacks (vm, data, parentData) {
6575
if (parentData.on) {
6676
updateListeners(parentData.on, data.on || {}, (event, handler) => {
6777
vm.$on(event, handler)
@@ -140,10 +150,7 @@ export function renderMixin (Vue) {
140150
vnode.key = _renderKey
141151
// update parent data
142152
if (_renderData) {
143-
const data = vnode.data
144-
mergeParentAttrs(this, data, _renderData)
145-
mergeParentDirectives(this, data, _renderData)
146-
updateParentCallbacks(this, data, _renderData)
153+
mergeParentData(this, vnode.data, _renderData)
147154
}
148155
return vnode
149156
}

Diff for: src/runtime/instance/state.js

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function initProps (vm) {
3636
}
3737

3838
export function getPropValue (data, key) {
39+
if (!data) return
3940
const altKey = hyphenate(key)
4041
return getPropValueFromHash(data.attrs, key, altKey) ||
4142
getPropValueFromHash(data.props, key, altKey)

0 commit comments

Comments
 (0)