1

I want to make a question solving screen using v-window. I keep my questions in a questionlist array. Clicking on the next button moves to the next window. I don't want it to go back to the beginning when it comes to the last question. I wrote clickable for this and bind it with disabled on the button. But when i do this, my button is disabled directly.

<v-btn @click="next" :disabled="clickable" v-model="terms">
                <v-icon x-large>mdi-arrow-right-thick</v-icon>
 </v-btn>


 
 methods: {
    next() {
      this.onboarding =
        this.onboarding + 1 === this.length ? 0 : this.onboarding + 1;
    },
  },

watch: {
    clickable: function () {
      const length = this.questionList.length;
      if (this.onboarding == length) {
        return !this.terms;
      }
      return this.terms;
    },
  },
0

2 Answers 2

1

I think you just need to use a computed as

computed: {
  clickable: function() {
    return (this.onboarding === this.questionList.length) ? true : false;
  }
}

Then you can check and modification as your needs.

Sign up to request clarification or add additional context in comments.

Comments

1

You shouldn't be using a watcher, but a computed property instead, because you want the value of clickable to be reactive based on changes. It does not make sense to have return statements on the watcher, and binding a watcher in your template will always return a truthy value.

Therefore, computed property is the way to go:

computed: {
    clickable: function () {
        const length = this.questionList.length;
        if (this.onboarding == length) {
            return !this.terms;
        }
        return this.terms;
    },
},

The documentation has a guide on when to use computed property vs watch.

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.