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...

贡献者指南