2017-07-20 121 views
1
<button class="navbar__dropdown-toggle" :aria-expanded="active"></button> 

我試圖綁定aria-expanded一個下拉菜單的狀態。不幸的是,當使用屏幕閱讀器(對於視障者)時,聽寫並不表示它是非擴展下拉菜單,因爲移除了錯誤的屬性。你如何強制Vue使用v-bind顯示虛假屬性?

有什麼辦法可以強迫虛假的屬性留下來嗎?

回答

1

貌似從W3C specaria-expanded值可以是真或假。所以在你的模板中你可以做到這一點。

<button class="navbar__dropdown-toggle" :aria-expanded="active ? 'true' : 'false'">expanded</button> 

工作example

1

我只是假設active是可變的,最直接的答案是!!active

+0

我認爲這是一個布爾值在他的情況下,所以不需要施放...只使用「活動」就足夠了。但是這也適用。 –