Skip to content
Advertisement

How can I disable a link in the vue component?

My html like this :

JavaScript

My javascript like this :

JavaScript

Demo and full code like this : https://jsfiddle.net/q7xcbuxd/221/

I try like that. But if I click button add, it’s not disabled

How can I solve this problem?

Advertisement

Answer

Since you are using boostrap, the proper way to disable a (anchor) button is not to set .disabled = true, but to add a disabled class.

Two other notes. You probably want to prevent the default behavior of the click event, so use @click.prevent. Also, if you don’t have additional arguments, you don’t need to use ="add($event)", just ="add" will suffice.

Demo below:

JavaScript
JavaScript
JavaScript

You can also go pure Vue and use a class binding:

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement