Browse Source

fix:when using object syntax in v-bind, special attribute have no effect

dev
gebilaoxiong 8 years ago
committed by Evan You
parent
commit
d33c1250ee
  1. 1
      flow/vnode.js
  2. 14
      src/core/instance/render-helpers/bind-object-props.js
  3. 11
      src/core/instance/state.js
  4. 4
      src/core/vdom/create-element.js
  5. 5
      src/shared/util.js

1
flow/vnode.js

@ -35,6 +35,7 @@ declare interface VNodeData {
key?: string | number; key?: string | number;
slot?: string; slot?: string;
ref?: string; ref?: string;
is?: string;
pre?: boolean; pre?: boolean;
tag?: string; tag?: string;
staticClass?: string; staticClass?: string;

14
src/core/instance/render-helpers/bind-object-props.js

@ -1,7 +1,13 @@
/* @flow */ /* @flow */
import config from 'core/config' 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. * Runtime helper for merging v-bind="object" into a VNode's data.
@ -24,7 +30,11 @@ export function bindObjectProps (
} }
let hash let hash
for (const key in value) { for (const key in value) {
if (key === 'class' || key === 'style') { if (
key === 'class' ||
key === 'style' ||
isReservedAttribute(key)
) {
hash = data hash = data
} else { } else {
const type = data.attrs && data.attrs.type const type = data.attrs && data.attrs.type

11
src/core/instance/state.js

@ -20,7 +20,8 @@ import {
isReserved, isReserved,
handleError, handleError,
validateProp, validateProp,
isPlainObject isPlainObject,
isReservedAttribute
} from '../util/index' } from '../util/index'
const sharedPropertyDefinition = { const sharedPropertyDefinition = {
@ -54,12 +55,6 @@ export function initState (vm: Component) {
if (opts.watch) initWatch(vm, opts.watch) if (opts.watch) initWatch(vm, opts.watch)
} }
const isReservedProp = {
key: 1,
ref: 1,
slot: 1
}
function checkOptionType (vm: Component, name: string) { function checkOptionType (vm: Component, name: string) {
const option = vm.$options[name] const option = vm.$options[name]
if (!isPlainObject(option)) { if (!isPlainObject(option)) {
@ -84,7 +79,7 @@ function initProps (vm: Component, propsOptions: Object) {
const value = validateProp(key, propsOptions, propsData, vm) const value = validateProp(key, propsOptions, propsData, vm)
/* istanbul ignore else */ /* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
if (isReservedProp[key] || config.isReservedAttr(key)) { if (isReservedAttribute(key) || config.isReservedAttr(key)) {
warn( warn(
`"${key}" is a reserved attribute and cannot be used as component prop.`, `"${key}" is a reserved attribute and cannot be used as component prop.`,
vm vm

4
src/core/vdom/create-element.js

@ -57,6 +57,10 @@ export function _createElement (
) )
return createEmptyVNode() return createEmptyVNode()
} }
// object syntax in v-bind
if (isDef(data) && isDef(data.is)) {
tag = data.is
}
if (!tag) { if (!tag) {
// in case of component :is set to falsy value // in case of component :is set to falsy value
return createEmptyVNode() return createEmptyVNode()

5
src/shared/util.js

@ -90,6 +90,11 @@ export function makeMap (
*/ */
export const isBuiltInTag = makeMap('slot,component', true) 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 * Remove an item from an array
*/ */

Loading…
Cancel
Save