优化value属性绑定, 自动转为赋值绑定
parent
0f09245657
commit
fc585abcdf
|
@ -13,11 +13,13 @@ const MARKER = `{{^wkit${String(Math.random()).slice(-8)}^}}`
|
|||
const MARKER_MATCH = '?' + MARKER
|
||||
const NODE_MARKER = `<${MARKER_MATCH}>`
|
||||
|
||||
// 是否原始值
|
||||
const isPrimitive = value =>
|
||||
value === null || (typeof value != 'object' && typeof value != 'function')
|
||||
value === null || (typeof value !== 'object' && typeof value !== 'function')
|
||||
const isArray = Array.isArray
|
||||
const isIterable = value =>
|
||||
value ? isArray(value) || typeof value[Symbol.iterator] === 'function' : false
|
||||
|
||||
const SPACE_CHAR = `[ \n\f\r]`
|
||||
const ATTR_VALUE_CHAR = `[^ \n\f\r"'\`<>=]`
|
||||
const NAME_CHAR = `[^\\s"'>=/]`
|
||||
|
@ -572,6 +574,10 @@ class AttributePart {
|
|||
} else {
|
||||
elem.removeAttribute(attr)
|
||||
}
|
||||
} else {
|
||||
// value 绑定, 特殊处理
|
||||
if (attr === 'value') {
|
||||
elem.value = value
|
||||
} else {
|
||||
if (value === null || value === void 0) {
|
||||
elem.removeAttribute(attr)
|
||||
|
@ -580,6 +586,7 @@ class AttributePart {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 赋值属性
|
||||
class PropertyPart extends AttributePart {
|
||||
|
|
Loading…
Reference in New Issue