In devtools with Vue2 I can access my components methods by selecting a component in vue devtools and then type $vm0.myMethod() in the console.
export default {
// ...
methods: {
myMethod() {
console.log('hello');
},
}
// ...
}
Now I'm using Vue3 with options API. How can I still access my component methods?
Given that the methods are specified in
methodsfor options API: {For composition API, it's presumed that component methods are returned from setup function:
This is implicitly done with
script setupsyntax:Here only
publicMethodis available on component ref. WhileprivateMethodandpublicMethodare exposed on internal component instance, which can be accessed asgetCurrentInstance().proxy.privateMethod, etc inside setup block, and as devtools$vm.proxyvia Vue devtools.If there's a chance that
justLocalFunctionneeds to be accessed later, returning it from setup function will make it easier for testing and debugging.