Hello I am working with Vuejs. I am assigning class names dynamically based on my project requirement, in a loop
:class="`card-${menu.name}`"
Where menu.name can be alpha, beta,zeta etc.
Now I want to add event listener to each class differently like do a1 when click on class card-alpha, do a2 when click on class card-beta and so on. Please see that I cannot use @click="myfunc" since I want different things to be done on each different class, so its something else. Can you help me with this. Thanks a lot
Here is the code which I am using and which wont work as it only runs once when the code is mounted. So how to trigger this function everytime on click?
mounted() {
document.querySelector('.card-alpha').addEventListener('click', () => { this.$state.val = 1; });
document.querySelector('.card-beta').addEventListener('click', () => { this.$state.val = 2; });
},
mounted() { document.querySelector('.card-alpha').addEventListener('click', () => { this.$state.val = 1; }); document.querySelector('.card-beta').addEventListener('click', () => { this.$state.val = 2; }); },this is inside mounted function. How should I trigger it everytime the button is clicked?