0

I'm creating a stepper component with a v-for loop, which currently works without an issues:

<li
    v-for="(step, index) in stepper"
    :key="step.id"
    class="goals-modal__step"
    :class="[{'is--selected': index === activeSlide }, {'is--visited': activeSlide > index}]"
>
    {{ step.stage }}
</li>

Data object:

data: () => ({
    activeSlide: 0,
}

This is working as expected.

However, when I try to pass the argument(index) from the v-for loop to a computed method so that I can return the class bindings for dynamic class logic (this will become more complex), I get an error: "[Vue warn]: Error in render: "TypeError: _vm.getClasses is not a function".

Updated code:

<li
    v-for="(step, index) in stepper"
    :key="step.id"
    :class="stepProgression(index)"
>
    {{ step.stage }}
</li>

And this is the computed method:

stepProgression(index) {
    return {
        'is--selected': index === this.activeSlide,
        'is--visited': this.activeSlide > index
    }
}

Does someone know what the issue us here? Any help much appreciated :)

1 Answer 1

0

Computed properties cannot receive arguments, so all you need to fix you code is move your property(function/method actually) to methods section like so:

methods: {
  stepProgression(index) {
      return {
          'is--selected': index === this.activeSlide,
          'is--visited': this.activeSlide > index
      }
  },
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.