Subscribe on changes!

When I create a component using the `setup` syntax sugar, I can't get the instance of the current component

avatar
Dec 28th 2021

Version

3.2.26

Reproduction link

sfc.vuejs.org/

Steps to reproduce

Im sorry, SFC Playground doesn't has console. You can open this code in your browser,.

  1. set ref to <Comp ref="compRef" /> and <SetupComp ref="setupCompRef" />
  2. open console, compRef has value, but SetupComp doesn't

So why?

What is expected?

compRef has value, SetupComp also has value

What is actually happening?

compRef has value, but SetupComp doesn't


By the way, when I tried to debug in the browser after writing code using the setup syntax sugar, I found myself in hell. my god

avatar
Dec 29th 2021

Seems to work well:

[vite] connecting...
App.vue:16 watchEffect:compRef null
App.vue:20 watchEffect:setupCompRef null
App.vue:16 watchEffect:compRef Proxy {…}[[Handler]]: Object[[Target]]: Object[[IsRevoked]]: false
App.vue:20 watchEffect:setupCompRef Proxy {__v_skip: true}[[Handler]]: Object[[Target]]: Proxy[[IsRevoked]]: false
client:206 [vite] connected.
avatar
Dec 30th 2021

Seems to work well:

[vite] connecting...
App.vue:16 watchEffect:compRef null
App.vue:20 watchEffect:setupCompRef null
App.vue:16 watchEffect:compRef Proxy {…}[[Handler]]: Object[[Target]]: Object[[IsRevoked]]: false
App.vue:20 watchEffect:setupCompRef Proxy {__v_skip: true}[[Handler]]: Object[[Target]]: Proxy[[IsRevoked]]: false
client:206 [vite] connected.

just like this,I want to use some variables from a file that I created with the setup . I used defineExpose to meet my requirements

avatar
Mar 13th 2023

你学要通过defineExpose暴露数据