Skip to content

How to access variable in "setup" in a closure that has a parameter with the same name? #9917

Discussion options

You must be logged in to vote

The issue with the original code lies in the attempt to use this within the defineExpose function. In Vue 3, when using the Composition API with <script setup>, you don't have access to this inside the script. Instead, you directly reference the reactive variables created with ref.

In your case, apple and modal are both refs, so you should use apple.value and modal.value to access and modify their values. The corrected code reflects this adjustment, eliminating the attempt to use this within the defineExpose function.

In the defineExpose function, you can directly reference the apple ref without using this. Here's the corrected code:

<script setup>
import { ref } from "vue"

const apple =…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kkqy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants