Vue.component('button-counter', {
template: '<button v-on:click="increment()">{{ counter }}</button>',
data: function () {
return {
counter: 0
}
},
methods: {
increment: function () {
this.counter += 1
}
},
})
For example, in the above component, I hope that the event v-on listens to is passed by the parent component, instead of writing it as click here. How should I write it?
Of course I know how to use props to pass, I want to know how to write v-on later. If you write propname directly, Vue will think that the event to be monitored is propname, not the specific event.
The questioner has special needs. If so, you may have to use
render
instead oftemplate
:Parent components pass parameters to subcomponents through props. Props can be functions, so you can pass a function to subcomponents