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
I use this pattern:
Template:
example('close')(arg)"
@play="(arg) => example('next')(arg)"
@stop="(arg) => example('back')(arg)"/>
Script:
...
methods: {
test () {
this.info('open')('test');
},
info (arg) {
console.table({omg: [arg, '!']});
},
example (arg) {
let self = this;
const methods = {
open (arg) {self.info(arg);},
close (arg) { return self.example('play')(arg)},
play (arg) {console.log(self, this)},
stop () {console.error('Lo1')},
};
if (!Object.keys(methods).includes(arg)) return () => false;
return methods[arg];
},
}
...
And second case:
Script:
const fabric = (arg, foo, context) => {
const methods = foo(context);
if (!Object.keys(methods).includes(arg)) return () => false;
return methods[arg];
};
export default {
...
methods: {
test () {
this.info('open')('test');
},
info (arg) {
console.table({omg: [arg, '!']});
},
example (arg) {
return fabric(arg, (cnx)=>({
open (arg) {cnx.info(arg);},
close (arg) { return cnx.example('play')(arg)},
play (arg) {console.log(cnx, this)},
stop () {console.error('Lo1')},
}), this);
},
}
...
}
Also, I think this is not a good practice, but it works and makes my work easier.