console.log(this.$refs.empty)
- 发布:2026-03-03 11:27
- 更新:2026-03-03 11:27
- 阅读:18
产品分类: uniapp/小程序/鸿蒙元服务
PC开发环境操作系统: Mac
PC开发环境操作系统版本号: mac m1芯片
HBuilderX类型: 正式
HBuilderX版本号: 4.87
第三方开发者工具版本号: 4.87
基础库版本号: 2.0.2-4080720251210002
项目创建方式: HBuilderX
示例代码:
操作步骤:
正常获取组件的$refs
正常获取组件的$refs
预期结果:
希望获取到组件的$refs实例
希望获取到组件的$refs实例
实际结果:
无法获取到,还报warn
无法获取到,还报warn
bug描述:
元服务获取this.$refs.empty 会报warn ,并且获取不到自定义组件
warn 如下
[Vue warn]: Property or method "$" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.\n\n(found in pages/index/index.vue)
11:19:52.720 [Vue warn]: Property or method "type" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.\n\n(found in pages/index/index.vue)
11:19:52.720 [Vue warn]: Property or method "style" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.\n\n(found in pages/index/index.vue)
11:19:52.720 [Vue warn]: Property or method "getPropertyValue" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.\n\n(found in pages/index/index.vue)
1 个回复
Ask小助手 - Ask社区AI助手
作为 DCloud 官方人员,我对该 bug 反馈进行如下评审:
✅ 一、反馈内容完整性评估
console.log(this.$refs.empty),未提供组件模板、ref 绑定方式、组件注册方式等关键信息。mounted中调用、是否为自定义组件等。⚠️ 二、是否误报或已知限制
根据知识库内容:
$refs只能用于获取自定义组件,不能用于获取内置组件(如view、text);$refs可能为空;v-if或异步渲染,需在this.$nextTick中访问$refs;$、style、type未定义)更像是 模板语法错误 或 数据未声明,而非$refs本身的问题。✅ 三、是否为基本概念问题
从 warn 内容来看:
这类错误通常是因为模板中错误地使用了未定义的变量(如
$style、$type等),而非$refs本身的问题。建议用户检查模板中是否存在如下错误写法:✅ 四、建议用户补充的信息
为确认是否为 bug,请用户补充以下内容:
<empty ref="empty" />?empty是否为自定义组件?是否已注册?mounted()或this.$nextTick()中访问?✅ 五、结论与建议
mounted或$nextTick中访问;$style、$type);如需进一步协助,请补充上述信息或上传复现工程至 DCloud 社区。
要回复问题请先登录或注册
公告
更多>相关问题