javascript - 如何在vuejs中用循环包装2个或更多的html元素

标签 javascript php html laravel vue.js

我想包装 2 个 html 元素

这是我在vuejs中的代码

<tr>
    <th v-for="(item9,index) in product_all" :key="item9.id"><center>Qty</center></th>
    <th v-for="(item99,index) in product_all" :key="item99.id"><center>Amount</center></th>
</tr>

这就是我想要的(在 laravel blade 中)

<tr>

    @foreach($dataProduct['byShowTanggal'] as $row)

        <th>Qty</th>

        <th>Amount</th>

    @endforeach
</tr>

最佳答案

你可以挂v-for关闭<template>元素。

<tr>
  <template v-for="item in product_all">
    <th :key="item.id + 'Qty'"><center>Qty</center></th>
    <th :key="item.id + 'Amount'"><center>Amount</center></th>
  </template>
</tr>

<template>是一个特殊元素,不会创建相应的 DOM 节点。

https://v2.vuejs.org/v2/guide/list.html#v-for-on-a-lt-template-gt

我还调整了您的元素的键,以确保它们对于这两个元素是不同的。

关于javascript - 如何在vuejs中用循环包装2个或更多的html元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56800973/

相关文章:

php - 从mysql的不同列中选择值,我怎么知道哪个是哪个?

javascript - 自动刷新 Controller 和 View Yii

php - 遍历数据库并使用 foreach 循环更新字段

javascript - 我的自动表单不会输出正确的值

javascript - 通过收集迭代时的 meteor 延迟

javascript - 50 === 50 : false. 50 == 50 : true?

javascript - 如何在TinyMCE上创建选择按钮?

html - 如何在固定宽度的 div 中居中动态宽度按钮?

html - 停止滚动条覆盖自动溢出的 div 内容

html - 我可以锁定 Twitter Bootstrap 表中的第一列吗?