I am pretty new to Vue.js.
I have a requirement wherein I want to bind events to the generic button template.
I tried using the below method.
Vue.component('ac-btn', {
props: [
'clickevent'
],
methods: {
greet: function () {
alert("I am Called");
}
},
template: '<button type="button" :click="clickevent" class="btn btn-secondary btn-sm"><slot>button</slot></button>'
});
But the click even is not called. Any idea of how to bind the click event to generic button template dynamically?
Edit:
@Saurabh
I tried your suggestion above and below is how it looks in my project.
Vue.component('ac-parent', {
methods: {
greet: function () {
alert("Hiey");
}
},
template: `<div class="container-fluid">
<div class="row">
<div class="col-lg-3 col-md-4">
<div>
<ac-child :onClick="greet">Custom value to replace generic slot value</ac-child>
</div>
</div>
</div>`
});
Vue.component('ac-child', {
template: '<button type="button" @click="clickevent" class="btn btn-secondary btn-sm"><slot>button</slot></button>'
});
Still this doesn't work. Am I doing something wrong?