新聞中心
信息

大悟網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁設計、網(wǎng)站建設、微信開發(fā)、APP開發(fā)、自適應網(wǎng)站建設等網(wǎng)站項目制作,到程序開發(fā),運營維護。創(chuàng)新互聯(lián)公司2013年成立到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設就選創(chuàng)新互聯(lián)。
這是一個低級的內(nèi)部 API 更改,不會影響大多數(shù)開發(fā)人員。
#概覽
下面是對這些變化的高層次總結(jié):
- 刪除枚舉 attribute 的內(nèi)部概念,并將這些 attribute 視為普通的非布爾 attribute
- 重大改變:如果值為布爾值,則不再刪除 attribute
false。相反,它被設置為 attr=“false”。移除 attribute,使用null或者undefined。
如需更深入的解釋,請繼續(xù)閱讀!
#2.x 語法
在 2.x,我們有以下策略來強制 v-bind 的值:
- 對于某些 attribute/元素對,Vue 始終使用相應的 IDL attribute(property):比如
value的,,``,等等。 - 對于“布爾 attribute”和 xlinks,如果它們是
falsy的,Vue 會移除它們 (undefined,nullorfalse) 另外加上它們 (見這里和這里)。 - 對于“枚舉 attribute” (目前
contenteditable,draggable和spellcheck),Vue 會嘗試強制將它們串起來 (目前對contenteditable做了特殊處理,修復 vuejs/vue#9397)。 - 對于其他 attribute,我們移除了
falsy值 (undefined,null,orfalse) 并按原樣設置其他值 (見這里)。
下表描述了 Vue 如何使用普通非布爾 attribute 強制“枚舉 attribute”:
| 綁定表達式 | 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" |
從上表可以看出,當前實現(xiàn) true 強制為 'true' 但如果 attribute 為 false,則移除該 attribute。這也導致了不一致性,并要求用戶在非常常見的用例中手動強制布爾值為字符串,例如 aria-* attribute 像 aria-selected,aria-hidden,等等。
#3.x 語法
我們打算放棄“枚舉 attribute”的內(nèi)部概念,并將它們視為普通的非布爾 HTML attribute。
- 這解決了普通非布爾 attribute 和“枚舉 attribute”之間的不一致性
- 它還可以使用
'true'和'false'以外的值,甚至可以使用contenteditable等 attribute 的關(guān)鍵字`
對于非布爾 attribute,如果 attribute 為 false,Vue 將停止刪除它們,相反強制它們?yōu)?'false'。
- 這解決了
true和false之間的不一致性,并使輸出aria-*attributes 更容易
下表描述了新行為:
| 綁定表達式 | 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 的強制保持不變。
#遷移策略
#枚舉 attribute
缺少枚舉 attribute 和 attr="false" 可能會產(chǎn)生不同的 IDL attribute 值 (將反映實際狀態(tài)),描述如下:
| 缺少枚舉attr | IDL attr & 值 |
|---|---|
contenteditable | contentEditable → 'inherit' |
draggable | draggable → false |
spellcheck | spellcheck → true |
為了保持原有的行為,并且我們將強制使用 false 為 'false',在 3.x Vue 中,開發(fā)人員需要將 v-bind 表達式解析為 false 或 'false',表示 contenteditable 和 spellcheck。
在 2.x 中,枚舉 attribute 的無效值被強制為 'true'。這通常是無意的,不太可能大規(guī)模依賴。在 3.x 中,應顯式指定 true 或 'true'。
#將 false 強制為 'false' 而不是刪除 attribute
在 3.x,null 或 undefined 應用于顯式刪除 attribute。
#2.x 和 3.x 行為的比較
| 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" |
標題名稱:創(chuàng)新互聯(lián)VUE3教程:Vue3.0attribute強制行為
分享URL:http://fisionsoft.com.cn/article/dhhhgps.html


咨詢
建站咨詢
