Skip to content

Commit

Permalink
fix:when using object syntax in v-bind, special attribute have no effect
Browse files Browse the repository at this point in the history
  • Loading branch information
gebilaoxiong authored and yyx990803 committed Jun 16, 2017
1 parent 8a2c514 commit d33c125
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions flow/vnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ declare interface VNodeData {
key?: string | number;
slot?: string;
ref?: string;
is?: string;
pre?: boolean;
tag?: string;
staticClass?: string;
Expand Down
14 changes: 12 additions & 2 deletions src/core/instance/render-helpers/bind-object-props.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/* @flow */

import config from 'core/config'
import { isObject, warn, toObject } from 'core/util/index'

import {
warn,
isObject,
toObject,
isReservedAttribute
} from 'core/util/index'

/**
* Runtime helper for merging v-bind="object" into a VNode's data.
Expand All @@ -24,7 +30,11 @@ export function bindObjectProps (
}
let hash
for (const key in value) {
if (key === 'class' || key === 'style') {
if (
key === 'class' ||
key === 'style' ||
isReservedAttribute(key)
) {
hash = data
} else {
const type = data.attrs && data.attrs.type
Expand Down
11 changes: 3 additions & 8 deletions src/core/instance/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
isReserved,
handleError,
validateProp,
isPlainObject
isPlainObject,
isReservedAttribute
} from '../util/index'

const sharedPropertyDefinition = {
Expand Down Expand Up @@ -54,12 +55,6 @@ export function initState (vm: Component) {
if (opts.watch) initWatch(vm, opts.watch)
}

const isReservedProp = {
key: 1,
ref: 1,
slot: 1
}

function checkOptionType (vm: Component, name: string) {
const option = vm.$options[name]
if (!isPlainObject(option)) {
Expand All @@ -84,7 +79,7 @@ function initProps (vm: Component, propsOptions: Object) {
const value = validateProp(key, propsOptions, propsData, vm)
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
if (isReservedProp[key] || config.isReservedAttr(key)) {
if (isReservedAttribute(key) || config.isReservedAttr(key)) {
warn(
`"${key}" is a reserved attribute and cannot be used as component prop.`,
vm
Expand Down
4 changes: 4 additions & 0 deletions src/core/vdom/create-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export function _createElement (
)
return createEmptyVNode()
}
// object syntax in v-bind
if (isDef(data) && isDef(data.is)) {
tag = data.is
}
if (!tag) {
// in case of component :is set to falsy value
return createEmptyVNode()
Expand Down
5 changes: 5 additions & 0 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export function makeMap (
*/
export const isBuiltInTag = makeMap('slot,component', true)

/**
* Check if a attribute is a reserved attribute.
*/
export const isReservedAttribute = makeMap('key,ref,slot,is')

/**
* Remove an item from an array
*/
Expand Down

0 comments on commit d33c125

Please sign in to comment.