uni-app icon indicating copy to clipboard operation
uni-app copied to clipboard

this.$refs又获取不到值了

Open zhangmrit opened this issue 1 year ago • 8 comments
trafficstars

该bug曾在 https://github.com/dcloudio/uni-app/issues/4554 出现 后续我看到也有修复记录,在最新版4.15版本中改问题又出现,此次不仅在发布的结果,而且在调试发布到抖音小程序开发工具同样无法获取 this.$refs的值永远是{}

zhangmrit avatar Jun 07 '24 06:06 zhangmrit

是setup不好用吗

ywenhao avatar Jun 08 '24 03:06 ywenhao

总不能不管老项目吧😂

---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2024年06月08日 11:02 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [dcloudio/uni-app] this.$refs又获取不到值了 (Issue #4974) |

是setup不好用吗

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

zhangmrit avatar Jun 08 '24 03:06 zhangmrit

提供下复现工程或者单页面源码吧,vue2 还是 vue3 发布到抖音找不到?是 dev 还是 prod 有问题?

Otto-J avatar Jun 13 '24 11:06 Otto-J

之前那个issue就可以,dev和prod都没有,你随便写个组件也行

---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2024年06月13日 19:52 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [dcloudio/uni-app] this.$refs又获取不到值了 (Issue #4974) |

提供下复现工程或者单页面源码吧,vue2 还是 vue3 发布到抖音找不到?是 dev 还是 prod 有问题?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

zhangmrit avatar Jun 13 '24 11:06 zhangmrit

我使用下面 demo

index page

<template>
    <view>
        <div v-if="showCounter">
            <counter ref="counterRef" />
        </div>
        <button @click="toggle">toggle</button>
        <button @click="add">+</button>
    </view>
</template>

<script>
import counter from '../../components/counter.vue';

export default {
    components: {
        counter,
    },
    data() {
        return {
            showCounter: false,
        }
    },
    methods: {
        toggle() {
            this.showCounter = !this.showCounter;
        },
        add() {
            // 这里 this.$refs 拿不到 counterRef
            this.$refs.counterRef.plus();
        },
    }
}
</script>

<style></style>

对应的子组件

<template>
  <view>
    {{ counter }}
  </view>
</template>

<script>
export default {
  name: 'counter',
  data() {
    return {
      counter: 0,
    };
  },
  methods: {
    plus() {
      this.counter++;
    },
  },
};
</script>

<style></style>

使用 vue2/vue3 运行到抖音真机调试,先点击 toggle 再点击 add,发现可以正常自增。你具体描述下你的问题吧

Otto-J avatar Jun 13 '24 13:06 Otto-J

有可能真机有,我是开发者工具没有,谢谢,我试试

---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2024年06月13日 21:00 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [dcloudio/uni-app] this.$refs又获取不到值了 (Issue #4974) |

我使用下面 demo

index page

对应的子组件

使用 vue2/vue3 运行到抖音真机调试,先点击 toggle 再点击 add,发现可以正常自增。你具体描述下你的问题吧

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

zhangmrit avatar Jun 13 '24 13:06 zhangmrit

有可能真机有,我是开发者工具没有,谢谢,我试试 ---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2024年06月13日 21:00 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [dcloudio/uni-app] this.$refs又获取不到值了 (Issue #4974) | 我使用下面 demo index page 对应的子组件 使用 vue2/vue3 运行到抖音真机调试,先点击 toggle 再点击 add,发现可以正常自增。你具体描述下你的问题吧 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

我在工具里遇到了。。一个vue2的项目从微信迁移抖音,$refs是{}

ys152452 avatar Jun 18 '24 11:06 ys152452

是的,开发者工具里没有

---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2024年06月18日 19:50 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [dcloudio/uni-app] this.$refs又获取不到值了 (Issue #4974) |

有可能真机有,我是开发者工具没有,谢谢,我试试 … ---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2024年06月13日 21:00 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [dcloudio/uni-app] this.$refs又获取不到值了 (Issue #4974) | 我使用下面 demo index page <divv-if="showCounter"><counterref="counterRef" /> @.@.="add">+ 对应的子组件 {{ counter }} 使用 vue2/vue3 运行到抖音真机调试,先点击 toggle 再点击 add,发现可以正常自增。你具体描述下你的问题吧 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

我在工具里遇到了。。一个vue2的项目从微信迁移抖音,$refs是{}

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

zhangmrit avatar Jun 18 '24 13:06 zhangmrit

2025-02-24 复测了 vue3 + 抖音模拟器表现正常,本问题关闭,如果仍有问题,请开新贴艾特我。复现工程在评论区已经准备好了。

Otto-J avatar Feb 24 '25 11:02 Otto-J

我也遇到了,vue2工程,请问怎么解决

SongBana avatar Mar 18 '25 02:03 SongBana

我也遇到了,vue2工程,请问怎么解决

换种写法,官方说没问题还能咋办

ys152452 avatar Mar 18 '25 02:03 ys152452

我也遇到了,vue2工程,请问怎么解决

换种写法,官方说没问题还能咋办

找到问题了,在编译后的app.json中有个一个component2:true 去掉就可以了,不知道在哪里加进去的

SongBana avatar Mar 18 '25 03:03 SongBana