uni-app Ref 定义的控件通过this.$refs获取不到
uni-app Ref 定义的控件通过this.$refs获取不到
项目信息 | 描述 |
---|---|
产品分类 | uniapp/小程序/微信 |
PC开发环境操作系统 | Windows |
PC开发环境操作系统版本号 | Win10 |
HBuilderX类型 | 正式 |
HBuilderX版本号 | 3.96 |
第三方开发者工具版本号 | 1.06.2307260 |
基础库版本号 | 3.2.1 |
项目创建方式 | HBuilderX |
示例代码:
<template >
<view ref="keyBoard11" class="content">
<text class="title" @click="onBind()">{{title}}</text>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
},
methods: {
onBind(){
console.log(">>>>>>>>>>@>",this.$refs)
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
### 操作步骤:
```html
<template >
<view ref="keyBoard11" class="content">
<text class="title" @click="onBind()">{{title}}</text>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
},
methods: {
onBind(){
console.log(">>>>>>>>>>@>",this.$refs)
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
### 预期结果:
想要通过refs获取组件
实际结果:
实际结果为{}(为空),就算指定组件也是undefined。
### bug描述:
甚至连官方示例也不能够正常运行,https://uniapp.dcloud.net.cn/uniCloud/unicloud-city-select.html#function,通过示例拿到的代码refs也是空
更多关于uni-app Ref 定义的控件通过this.$refs获取不到的实战教程也可以访问 https://www.itying.com/category-93-b0.html
3 回复
3.99版本也遇到这个问题了
更多关于uni-app Ref 定义的控件通过this.$refs获取不到的实战教程也可以访问 https://www.itying.com/category-93-b0.html
兄弟,这个问题解决了吗, 我也是这样的情况