I'm currently learning Vue 3 and the Composition API, and I'm wondering what the recommended way of defining a function is using the Composition API. In the official Vue 3 documentation, I noticed that they use regular functions to define methods and event handlers, like this:
import { defineComponent } from 'vue'
export default defineComponent({
setup() {
const message = 'Hello Vue!'
const handleClick = function(event) {
console.log(event.target)
}
return {
message,
handleClick
}
}
})
However, I've also seen examples online that use arrow functions instead, like this:
import { defineComponent } from 'vue'
export default defineComponent({
setup() {
const message = 'Hello Vue!'
const handleClick = (event) => {
console.log(event.target)
}
return {
message,
handleClick
}
}
})
I know that both approaches are valid, but I'm wondering if there's a recommended way of doing it using the Composition API, or if it's mostly a matter of personal preference. Are there any benefits or drawbacks to using one approach over the other? Does it depend on the specific use case or context?
Any insights or advice would be greatly appreciated. Thank you in advance!