doubleyong
管理员
管理员
  • 最后登录2025-12-02
  • 发帖数1198
  • 最爱沙发
  • 喜欢达人
  • 原创写手
  • 社区居民
  • 忠实会员
阅读:4994回复:0

[前端]【uniapp】uniapp中使用vue3 中的$refs打印为undefined

楼主#
更多 发布于:2022-07-21 15:17
使用uniapp + vue3 开发,用微信小程序调试,$refs.xxx 打印为undefined
代码如下:
import {
        ref,
        getCurrentInstance,
        onMounted
    } from 'vue'
    export default {
        setup() {
            const {
                proxy , ctx 
            } = getCurrentInstance();
            onMounted(() => {
                console.log(ctx.$refs.commonRef);
            })
                   return {}
        }
    }

原因:

$refs , 在非h5端不支持

图片:bug3.jpg



官网说明:https://uniapp.dcloud.io/tutorial/vue3-api.html#%E5%AE%9E%E4%BE%8B-property

解决方案:

通过另外的方法去获取dom对象或值.
而我的需求是获取值 。 所以换了一个方法,使用v-model来使用

参考如下链接:

https://bugshouji.com/mybird/t15243
知识需要管理,知识需要分享
游客


返回顶部

公众号

公众号