$slots elements are not rendered if it derived by computed prop
See original GitHub issueVue.js version
2.0.0-rc.3
Reproduction Link
https://jsfiddle.net/ktsn/oc8g5dcm/6/
Steps to reproduce
Click “Add List” button.
What is Expected?
Both test1 and test2 components render the elements passed to $slots.
What is actually happening?
The test2 renders the elements but test1 is not.
Note that we can avoid this issue if adding cache: false
option for the computed option.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Computed Properties - Vue.js
Think of a computed property as declaratively describing how to derive a value based on other values - its only responsibility should be...
Read more >How to fix - Slot invoked outside of the render function in vue 3
To suppress the error you just need to move the code into a computed property or method called from within the template or...
Read more >Solving Common Vue Problems — Props and Dynamic ...
The computed property returns some data derived from the original data. In our example, we returned an array derived from the this.items array....
Read more >Vue.js - Template with parent scope not updating
When I change something inside of items after rendering, the child component doesn't recognize it. The reason is because the item.additionalData ...
Read more >Tracing or Debugging Vue.js Reactivity: The computed tree
Within this component tree, there will be computed properties (derived data). When this happens, the reactive path from the store data to the ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I ran into this problem and the solution to this one is simply using a getter method (i.e
getSlots()
) instead of hacks like adding a random property just so you can use a computed property and reference the said random property inside it.Referencing OP’s jsfiddle, instead of:
do this:
This solution applies to any other non-reactive properties and not only
$slots
That kind of warning would be hard to implement because there may be scenarios where someone uses
$slots
inside a computed property for a good reason, and only wants it to update when another, reactive value changes.So Vue would have to check weither only non-reactive elements are used, which is not worth it in my opinion.
We should rather make it clear in the guide and API docs that computed properties only react to changes references to
data
,props
and other computed properties.@chrisvfritz opinions?