I have the following element in my list.vue
file:
<a id="anchorLink"
class="button is-primary is-fullwidth-mobile mb-sm"
@click="functionA()">
<span>Call Function A</span>
</a>
And this is the function functionA
async functionA() {
// do something
},
All I want to do is disable the anchor link until functionA
processing is done, then only enable back the link.
So i tried all these options to disable it but no luck so far:
OPTION01:
async functionA() {
document.getElementById('anchorLink').disabled = true;
// do something
}
OPTION02: using .prevent
<a id="anchorLink"
class="button is-primary is-fullwidth-mobile mb-sm"
@click.prevent="functionA()">
<span>Call Function A</span>
</a>
OPTION03: using v-on:click.prevent
<a id="anchorLink"
class="button is-primary is-fullwidth-mobile mb-sm"
v-on:click.prevent="functionA()">
<span>Call Function A</span>
</a>
I don't get any console error when I tried all the options, but it still doesn't do the job.
Can someone please help me out here.
Keeping the code that you have provided in consideration. As far I understand your question you can disable the
<a>
link by assigning dynamic classes by binding it to data property of the class like:class
to youranchor
tag. Use object based class syntax for your<a>
tag and then toggle the class name with aboolean
value.Note: The Link will turn
red
in color when it is in disable phase and when function execution is complete it will turn back to it's original color. While it is red you won't be able to executefunctionA()
TEST IT HERE
Your vue markup
Vue Class
CSS
The
pointer-events
property defines whether or not an element reacts to pointer events. Not necessary to add but you can include it.Hope it helps!