VUEJS循环组件并立即获取发射数据

发布于 2025-02-06 19:19:34 字数 661 浏览 2 评论 0原文

我循环一个孩子的组件,该组件已发出数据并传递给父母的本地数据,但我的期望结果不是我得到的。它应该以这种增量为单位。示例

Index       Total
0             5
1             7
2             10
3             12

在这里我的代码:

<template>
  <div>
    <div v-for="data, index in myArr">
      <child-block-1
        :key="index"
        :data="data"
        @emittedData="total += $event"
      />
      <child-block-2 v-if="total > 10" />
    </div>
  </div>
</template>

total数据将添加发出的数据,但是当我检查总数时,总计总数始终为12。而不是增量。

还有其他解决方案可以得到我的预期结果吗?

I loop a child components that has emitted data and pass to local data in parent but my expectation result is not what i get. It should be in incremental like this. Example

Index       Total
0             5
1             7
2             10
3             12

here my code:

<template>
  <div>
    <div v-for="data, index in myArr">
      <child-block-1
        :key="index"
        :data="data"
        @emittedData="total += $event"
      />
      <child-block-2 v-if="total > 10" />
    </div>
  </div>
</template>

The total data will add the emitted data, but when i check the total it will always the overall total 12. not the incremental.

Is there any other solution for this to get what my expected result ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文