I'd like to group some of my Vue.js methods together in a sort of "submethod" class, but I only seem to be able to have single level methods.
For example, if I wanted to have a set of methods dealing purely with button actions:
new Vue({
el: '#app',
data: { },
methods: {
buttonHandlers: {
handler1: function() {
dosomething;
},
handler2: function() {
dosomething;
}
}
}
});
I would expect to be able to then use something like:
<button v-on:click="buttonHandlers.handler1">Click Me</button>
but nothing happens.
I have tried forcing the function to run by adding brackets:
<button v-on:click="buttonHandlers.handler1()">Click Me</button>
but I receive this console error:
Uncaught TypeError: scope.buttonHandlers.handler1 is not a function
I've setup a small https://jsfiddle.net/ozx9oc4c/ to demonstrate what I mean.
If anyone knows of a way to logically group functions under parent methods in Vue.js, rather than pages and pages of single level methods with no real structure, I'd be grateful for your knowledge.