I'm new to Vue.js 3, but I have a strange behavior accessing the “this” object in a component.
If my component is declared with the script setup
, the access to “this” object is always undefined, see the below code:
<script setup>
import { onMounted } from 'vue'
onMounted(() => {
console.info("Access KO: " + this)
})
</script>
If I use the export default
, everything works fine, see the below code:
<script>
export default {
mounted() {
console.info("Access OK: " + JSON.stringify(this) + "<<")
}
}
</script>
Do you have any idea?
Thanks and regards. Giuseppe