question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$slots elements are not rendered if it derived by computed prop

See original GitHub issue

Vue.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:closed
  • Created 7 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

10reactions
xxRockOnxxcommented, Mar 3, 2020

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:

computed: {
  firstSlot() {
    return this.$slots.default
  }
}

do this:

methods: {
  getFirstSlot() {
    return this.$slots.default
  }
}

This solution applies to any other non-reactive properties and not only $slots

4reactions
LinusBorgcommented, Aug 25, 2016

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?

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found