vuejs/v2.vuejs.org

Add reactivity warning to $slots API page

開放

#2,662 建立於 2020年8月10日

 (3 則留言) (0 個反應) (1 位負責人)JavaScript (3,550 個分叉)batch import
good first issue

倉庫指標

星標
 (5,072 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Summary Slots are not reactive, but the docs do not reflect this

Proposed solution Add a warning in all versions of the docs on the $slots page, where its reactivity seems most likely to be referenced from a user perspective

Further explanation While trying to debug an issue with a computed property that had this.$slots.default as a dependency in a jsx component, I was unable to determine whether the slots were getting updated data via console.logs; it appeared that slots were not reactive, but I couldn't confirm by printing (due to the fact that no updates would trigger as a result of $slots not being reactive).

A colleague found a response from @LinusBorg on this issue, which seems to confirm slots have never been and will never be reactive, and it appears as though the TODO to update the docs as necessary never made it in, so I'd like to rectify that now 🙂

Aside In the same thread, @chrisvfritz suggests moving the data to props or another reactive option if reactivity is needed; this may be a good tip to include but I'm not sure whether he means in lieu of $slots or to pass the $slots to props or something else...

貢獻者指南