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.

slot with slot-scope cannot be accessed via $slots

See original GitHub issue

Version

2.5.17

Reproduction link

Steps to reproduce

Create a component with slot

<template>
  <div>
    <slot></slot>
  </div>
</template>

<script>
export default {
  name: 'TestComponent',
  created () {
    console.log(this.$slots.default)
  }
}
</script>

Use it with two slot components, one has slot-scope attribute and the other one do not

<template>
  <test-component>
    <p slot-scope="props">1</p>
    <p>2</p>
  </test-component>
</template>

Then will found this.$slots.default can only access the second VNode.

And if we removed slot-scope attribute from the first

element, both of them shows in this.$slots.default.

What is expected?

I’m not sure whether this is the limitation of slot-scope and is there any other methods to get slot VNode with slot-scope?

What is actually happening?

cannot access slot with slot-scope

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Justineocommented, Nov 6, 2018

Scoped slots are exposed via this.$scopedSlots.

0reactions
Yuyz0112commented, Nov 7, 2018

Yes, this is a good alternative I have already try, just trying to provide some more straightforward API.

Thanks a lot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Access this.$slots while using v-slot (scoped-slot)
$slots being empty and breaking my code. How is it possible to access the DOM element of a slot that is using a...
Read more >
Slots - Vue.js
Scoped Slots​​ As discussed in Render Scope, slot content does not have access to state in the child component. However, there are cases...
Read more >
Understanding scoped slots in Vue.js - Binarcode
A scoped slot is a special type of slot that functions as a reusable template (that can be passed data to) instead of...
Read more >
Using Slots In Vue.js - Smashing Magazine
To get access to the data passed to the slot, we specify the name of the scope variable with the value of the...
Read more >
How To Use Scoped Component Slots in Vue.js - DigitalOcean
For example, "firstScope" , properties passed into the <slot> will be accessible as {{firstScope.exampleProperty}} while secondScope" will be ...
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