Skip to content
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

popup 在Vue3中是否无法在组合式api中使用 #895

Closed
Bo-Teng opened this issue May 17, 2024 · 5 comments
Closed

popup 在Vue3中是否无法在组合式api中使用 #895

Bo-Teng opened this issue May 17, 2024 · 5 comments

Comments

@Bo-Teng
Copy link

Bo-Teng commented May 17, 2024

image
我尝试使用图中的方法去获取组件实例,但是在获取不到。
经过尝试只能使用选项式的方式去获取(如下图),如果暂时还不支持组合式建议在文档中说明一下,不然对像我这种刚接触uni app 还是挺迷茫的。
image

环境:
HBuilderX 4.15
window 10
微信开发者工具 stable 1.06.2402040

@julytian
Copy link

应该是this.$refs.popupRef.open()

@Bo-Teng
Copy link
Author

Bo-Teng commented May 24, 2024

应该是this.$refs.popupRef.open()

@julytian 这里是因为我根据示例改成了选项式(vue2那种范式)的方式,ref就变成了popup。

@Bo-Teng
Copy link
Author

Bo-Teng commented May 24, 2024

@julytian 如果使用组合式api(setup)就会导致获取不到这个组件的示例,但是自定义的组件时可以的。

@julytian
Copy link

@Bo-Teng ,vue3 setup 写法没有 this 了,你试下下面这种写法:

import { ref } from 'vue'
const popupRef = ref()
function open() {
 popupRef.value?.open()
}

@Bo-Teng
Copy link
Author

Bo-Teng commented May 24, 2024

@julytian 哥们谢谢你的指点,我发现了我问题是因为我没有导出这个popupRef

@Bo-Teng Bo-Teng closed this as completed May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants