W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
信息
這是一個(gè)低級(jí)的內(nèi)部 API 更改,不會(huì)影響大多數(shù)開發(fā)人員。
下面是對(duì)這些變化的高層次總結(jié):
false
。相反,它被設(shè)置為 attr=“false”。移除 attribute,使用 null
或者 undefined
。如需更深入的解釋,請(qǐng)繼續(xù)閱讀!
在 2.x,我們有以下策略來強(qiáng)制 v-bind
的值:
value
的 ,
,``,等等。falsy
的,Vue 會(huì)移除它們 (undefined
,null
or false
) 另外加上它們 (見這里和這里)。contenteditable
,draggable
和 spellcheck
),Vue 會(huì)嘗試強(qiáng)制將它們串起來 (目前對(duì) contenteditable
做了特殊處理,修復(fù) vuejs/vue#9397)。falsy
值 (undefined
,null
,or false
) 并按原樣設(shè)置其他值 (見這里)。下表描述了 Vue 如何使用普通非布爾 attribute 強(qiáng)制“枚舉 attribute”:
綁定表達(dá)式 | foo 正常 |
draggable 枚舉 |
---|---|---|
:attr="null" |
/ | draggable="false" |
:attr="undefined" |
/ | / |
:attr="true" |
foo="true" |
draggable="true" |
:attr="false" |
/ | draggable="false" |
:attr="0" |
foo="0" |
draggable="true" |
attr="" |
foo="" |
draggable="true" |
attr="foo" |
foo="foo" |
draggable="true" |
attr |
foo="" |
draggable="true" |
從上表可以看出,當(dāng)前實(shí)現(xiàn) true
強(qiáng)制為 'true'
但如果 attribute 為 false
,則移除該 attribute。這也導(dǎo)致了不一致性,并要求用戶在非常常見的用例中手動(dòng)強(qiáng)制布爾值為字符串,例如 aria-*
attribute 像 aria-selected
,aria-hidden
,等等。
我們打算放棄“枚舉 attribute”的內(nèi)部概念,并將它們視為普通的非布爾 HTML attribute。
'true'
和 'false'
以外的值,甚至可以使用 contenteditable
等 attribute 的關(guān)鍵字`
對(duì)于非布爾 attribute,如果 attribute 為 false
,Vue 將停止刪除它們,相反強(qiáng)制它們?yōu)?'false'
。
true
和 false
之間的不一致性,并使輸出 aria-*
attributes 更容易下表描述了新行為:
綁定表達(dá)式 | foo 正常 |
draggable 枚舉 |
---|---|---|
:attr="null" |
/ | / ? |
:attr="undefined" |
/ | / |
:attr="true" |
foo="true" |
draggable="true" |
:attr="false" |
foo="false" ? |
draggable="false" |
:attr="0" |
foo="0" |
draggable="0" ? |
attr="" |
foo="" |
draggable="" ? |
attr="foo" |
foo="foo" |
draggable="foo" ? |
attr |
foo="" |
draggable="" ? |
?: 變更
布爾 attributes 的強(qiáng)制保持不變。
缺少枚舉 attribute 和 attr="false"
可能會(huì)產(chǎn)生不同的 IDL attribute 值 (將反映實(shí)際狀態(tài)),描述如下:
缺少枚舉attr | IDL attr & 值 |
---|---|
contenteditable |
contentEditable → 'inherit' |
draggable |
draggable → false |
spellcheck |
spellcheck → true |
為了保持原有的行為,并且我們將強(qiáng)制使用 false
為 'false'
,在 3.x Vue 中,開發(fā)人員需要將 v-bind
表達(dá)式解析為 false
或 'false'
,表示 contenteditable
和 spellcheck
。
在 2.x 中,枚舉 attribute 的無效值被強(qiáng)制為 'true'
。這通常是無意的,不太可能大規(guī)模依賴。在 3.x 中,應(yīng)顯式指定 true
或 'true'
。
false
強(qiáng)制為 'false'
而不是刪除 attribute
在 3.x,null
或 undefined
應(yīng)用于顯式刪除 attribute。
Attributes | v-bind value 2.x |
v-bind value 3.x |
HTML 輸出 |
---|---|---|---|
2.x “枚舉attribute” i.e. contenteditable , draggable and spellcheck . |
undefined , false |
undefined , null |
removed |
true , 'true' , '' , 1 , 'foo' |
true , 'true' |
"true" |
|
null , 'false' |
false , 'false' |
"false" |
|
其他非布爾attribute eg. aria-checked , tabindex , alt , etc. |
undefined , null , false |
undefined , null |
removed |
'false' |
false , 'false' |
"false" |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: