Here is a basic example of a component in Vue 3:
<script>
import { defineComponent } from 'vue'
export default defineComponent({
name: 'Test',
setup(){
return{
one,
two
}
}
})
function one(){
console.log(this) //<-- Proxy{}
two()
}
function two(){
console.log(this) //<-- undefined
}
</script>
<template>
<a href="#" @click.prevent="one()">Start</a>
</template>
I am puzzled as to why this
is showing up as undefined
in the two()
function when it is called from the one()
function. Since both functions are returned within the setup()
, I would assume they would both have access to this
.
So, how can I obtain a reference to the component instance with this
inside my two()
function?