Subscribe on changes!

在script setup中使用getCurrentInstance生产无法获取setupState

avatar
Jun 8th 2023

Vue version

3.3.4

Link to minimal reproduction

https://play.vuejs.org/#__DEV__eNplkEFPhDAQhf/K2AuQrDRetRDNXvSqJl64VJhliaVtyhRNCP/dAdw1useZ982beTOJB+/zMaK4FWqoQ+cJBqToy8p2vXeBYIKAhx20SPsYAlp6sgNpW+MOyD3rT5jhEFwPCbskla1s7RiAfmihWEbT5BGNcfDmgmmukuwX6X6MmLt0T7O7E3fUtjH4igPtTVd/MJ5mUJQwsRVJyZvyUZu4+KwXpSdj3gWweDiDuXHtX0EbDHRu5WvsF9KEOTsyMS+XKrl9hf/BBWHvDRNcAajjTTlNa9B5VpKrtdtZHwnG6941aIpKsF6JTXqPRM7Cfb3EYOlfMMYIvwhWWcmN5kklz3vF/A32HJoO

Steps to reproduce

  1. dev环境下点击test click能正常获取msg
  2. prod环境下点击test click能无法获取msg

What is expected?

prod环境下点击test click能正常获取msg

What is actually happening?

No response

System Info

No response

Any additional comments?

No response

avatar
Jun 8th 2023

问题背景,项目需要做持久化缓存,需要获取类似vue2中的$data数据去存储

avatar
Jun 8th 2023
<script setup>
import { ref, getCurrentInstance, toRaw } from 'vue'

const msg = ref('Hello World!')
defineExpose({msg})
const instance = getCurrentInstance();
const handleTestClick = () => {
  console.log(instance.exposeProxy.msg)
}
</script>