Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Zero1306 opened this issue Jun 8, 2023 · 2 comments
Closed

Comments

@Zero1306
Copy link

Zero1306 commented Jun 8, 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

@Zero1306
Copy link
Author

Zero1306 commented Jun 8, 2023

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

@baiwusanyu-c
Copy link
Member

baiwusanyu-c commented Jun 8, 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>

@edison1105 edison1105 converted this issue into discussion #8516 Jun 8, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Sep 9, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants