Access slot-scope from computed property or method


#1

Hi,
is it possible to access the variable containing a slot-scope from within a computed property or a method?

Thanks!


#2

Hi.

Does this answer your question - vm-slots:


#3

Maybe i can’t figure it out in the docs but my usecase is: I wrote a renderless component that expose some data via scoped slot. I want to use that data to compute a classname object for the wrapping element.

i mean i can make it work by using the array syntax (or spread operator if you have the tools for that)

    <renderless-component>
      <div slot-scope={someState} 
        :class="[
          someComputedClassnames, 
         { 'extra-state-class': someState === true}
         ]">
       ...
      </div>
    </renderless-component>

This works (and solves the issue) but i was wondering if can use that someState inside the computed someComputedClassnames.

     computed: {
        someComputedClassnamess() {
          console.log(this);
          return {
            'base-class': true
            /**
              Is it possible to acess scoped slot props object in computed property?
            */
            //'extra-state-class': state === true,
          };
        }
      }

I wrote a codesandbox sample to illustrate the case!
Thanks in advance! :slight_smile:


#4

You can’t access those values from a computed property.


#5

Thanks for the clarification!