3

I have the following button that gets disabled if the user is in the first page:

<button :disabled="page==1" v-on:click="page=1;run()" class="page-link" :class="{'disabled' : disabled}">First</button>

However i would like to add the class .disabled if said button is disabled by Vue. Is it possible to do this through Vue?

2
  • you can also put the same condition directly to the class directive: :class="{'disabled' : page === 1}" Commented Dec 31, 2020 at 11:28
  • @Serg That worked, could you please create an answer so I can mark it as correct? Commented Dec 31, 2020 at 11:38

2 Answers 2

5

You can put the same condition directly to the class directive:

 :class="{'disabled' : page === 1}"
Sign up to request clarification or add additional context in comments.

1 Comment

It's an older answer, but thank you! This helped me.
-1

Try changing disabled to false in the onclick, something like this: v-on:click="page=1;run();!disabled" or v-on:click="page=1;run();disabled=false".

1 Comment

I dont have a disabled variable or prop, only the bind on the disabled attribute in the html to be disabled if a condition is met :disabled="page==1"

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.