mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-02 12:07:39 +08:00
only treat binding as domProps on specific elements (fix #4233)
This commit is contained in:
parent
f4df893828
commit
9a742cb423
@ -7,7 +7,7 @@ declare type CompilerOptions = {
|
|||||||
directives?: { [key: string]: Function }; // platform specific directives
|
directives?: { [key: string]: Function }; // platform specific directives
|
||||||
isUnaryTag?: (tag: string) => ?boolean; // check if a tag is unary for the platform
|
isUnaryTag?: (tag: string) => ?boolean; // check if a tag is unary for the platform
|
||||||
isReservedTag?: (tag: string) => ?boolean; // check if a tag is a native for the platform
|
isReservedTag?: (tag: string) => ?boolean; // check if a tag is a native for the platform
|
||||||
mustUseProp?: (attr: string) => ?boolean; // check if an attribute should be bound as a property
|
mustUseProp?: (tag: string, attr: string) => ?boolean; // check if an attribute should be bound as a property
|
||||||
isPreTag?: (attr: string) => ?boolean; // check if a tag needs to preserve whitespace
|
isPreTag?: (attr: string) => ?boolean; // check if a tag needs to preserve whitespace
|
||||||
getTagNamespace?: (tag: string) => ?string; // check the namespace for a tag
|
getTagNamespace?: (tag: string) => ?string; // check the namespace for a tag
|
||||||
transforms?: Array<Function>; // a list of transforms on parsed AST before codegen
|
transforms?: Array<Function>; // a list of transforms on parsed AST before codegen
|
||||||
|
@ -2,11 +2,7 @@
|
|||||||
|
|
||||||
export default function bind (el: ASTElement, dir: ASTDirective) {
|
export default function bind (el: ASTElement, dir: ASTDirective) {
|
||||||
el.wrapData = (code: string) => {
|
el.wrapData = (code: string) => {
|
||||||
return `_b(${
|
return `_b(${code},'${el.tag}',${dir.value}${
|
||||||
code
|
|
||||||
},${
|
|
||||||
dir.value
|
|
||||||
}${
|
|
||||||
dir.modifiers && dir.modifiers.prop ? ',true' : ''
|
dir.modifiers && dir.modifiers.prop ? ',true' : ''
|
||||||
})`
|
})`
|
||||||
}
|
}
|
||||||
|
@ -379,7 +379,7 @@ function processAttrs (el) {
|
|||||||
name = camelize(name)
|
name = camelize(name)
|
||||||
if (name === 'innerHtml') name = 'innerHTML'
|
if (name === 'innerHtml') name = 'innerHTML'
|
||||||
}
|
}
|
||||||
if (isProp || platformMustUseProp(name)) {
|
if (isProp || platformMustUseProp(el.tag, name)) {
|
||||||
addProp(el, name, value)
|
addProp(el, name, value)
|
||||||
} else {
|
} else {
|
||||||
addAttr(el, name, value)
|
addAttr(el, name, value)
|
||||||
|
@ -14,7 +14,7 @@ export type Config = {
|
|||||||
isReservedTag: (x?: string) => boolean;
|
isReservedTag: (x?: string) => boolean;
|
||||||
isUnknownElement: (x?: string) => boolean;
|
isUnknownElement: (x?: string) => boolean;
|
||||||
getTagNamespace: (x?: string) => string | void;
|
getTagNamespace: (x?: string) => string | void;
|
||||||
mustUseProp: (x?: string) => boolean;
|
mustUseProp: (tag?: string, x?: string) => boolean;
|
||||||
// internal
|
// internal
|
||||||
_assetTypes: Array<string>;
|
_assetTypes: Array<string>;
|
||||||
_lifecycleHooks: Array<string>;
|
_lifecycleHooks: Array<string>;
|
||||||
|
@ -201,6 +201,7 @@ export function renderMixin (Vue: Class<Component>) {
|
|||||||
// apply v-bind object
|
// apply v-bind object
|
||||||
Vue.prototype._b = function bindProps (
|
Vue.prototype._b = function bindProps (
|
||||||
data: any,
|
data: any,
|
||||||
|
tag: string,
|
||||||
value: any,
|
value: any,
|
||||||
asProp?: boolean
|
asProp?: boolean
|
||||||
): VNodeData {
|
): VNodeData {
|
||||||
@ -218,7 +219,7 @@ export function renderMixin (Vue: Class<Component>) {
|
|||||||
if (key === 'class' || key === 'style') {
|
if (key === 'class' || key === 'style') {
|
||||||
data[key] = value[key]
|
data[key] = value[key]
|
||||||
} else {
|
} else {
|
||||||
const hash = asProp || config.mustUseProp(key)
|
const hash = asProp || config.mustUseProp(tag, key)
|
||||||
? data.domProps || (data.domProps = {})
|
? data.domProps || (data.domProps = {})
|
||||||
: data.attrs || (data.attrs = {})
|
: data.attrs || (data.attrs = {})
|
||||||
hash[key] = value[key]
|
hash[key] = value[key]
|
||||||
|
@ -3,7 +3,14 @@
|
|||||||
import { makeMap } from 'shared/util'
|
import { makeMap } from 'shared/util'
|
||||||
|
|
||||||
// attributes that should be using props for binding
|
// attributes that should be using props for binding
|
||||||
export const mustUseProp = makeMap('value,selected,checked,muted')
|
export const mustUseProp = (tag: string, attr: string): boolean => {
|
||||||
|
return (
|
||||||
|
(attr === 'value' && (tag === 'input' || tag === 'textarea' || tag === 'option')) ||
|
||||||
|
(attr === 'selected' && tag === 'option') ||
|
||||||
|
(attr === 'checked' && tag === 'input') ||
|
||||||
|
(attr === 'muted' && tag === 'video')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export const isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck')
|
export const isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck')
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ describe('codegen', () => {
|
|||||||
it('generate v-bind directive', () => {
|
it('generate v-bind directive', () => {
|
||||||
assertCodegen(
|
assertCodegen(
|
||||||
'<p v-bind="test"></p>',
|
'<p v-bind="test"></p>',
|
||||||
`with(this){return _h('p',_b({},test))}`
|
`with(this){return _h('p',_b({},'p',test))}`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -151,9 +151,15 @@ describe('codegen', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('generate DOM props with v-bind directive', () => {
|
it('generate DOM props with v-bind directive', () => {
|
||||||
|
// input + value
|
||||||
|
assertCodegen(
|
||||||
|
'<input :value="msg">',
|
||||||
|
`with(this){return _h('input',{domProps:{"value":msg}})}`
|
||||||
|
)
|
||||||
|
// non input
|
||||||
assertCodegen(
|
assertCodegen(
|
||||||
'<p :value="msg">',
|
'<p :value="msg">',
|
||||||
`with(this){return _h('p',{domProps:{"value":msg}})}`
|
`with(this){return _h('p',{attrs:{"value":msg}})}`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user