dcloudio / uni-app

A cross-platform framework using Vue.js
https://uniapp.dcloud.io
Apache License 2.0
39.97k stars 3.62k forks source link

this.$refs又获取不到值了 #4974

Open zhangmrit opened 3 months ago

zhangmrit commented 3 months ago

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

ywenhao commented 3 months ago

是setup不好用吗

zhangmrit commented 3 months ago

总不能不管老项目吧😂

---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 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: @.***>

Otto-J commented 3 months ago

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

zhangmrit commented 3 months ago

之前那个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: @.***>

Otto-J commented 3 months ago

我使用下面 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,发现可以正常自增。你具体描述下你的问题吧

zhangmrit commented 3 months ago

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

---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 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: ***@***.***>
ys152452 commented 3 months ago

有可能真机有,我是开发者工具没有,谢谢,我试试 ---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 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是{}

zhangmrit commented 3 months ago

是的,开发者工具里没有

---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 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 @.@.="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: @.***>