[英]When list rendering a component, nested component data doesn't update
The list rendering on the parent component runs perfectly父组件上的列表渲染完美运行
<stock-card
class="col-sm"
v-for="(stock, index) in formattedStocks"
:stock="stock"
:key="index"
>
</stock-card>
On the nested component it only renders the first instance of the loop inside the modal component在嵌套组件上,它仅在模态组件内呈现循环的第一个实例
<p class="card-text text-success">{{ stock["name"] }}$</p>
<button
class="btn btn-danger rounded-pill"
data-bs-toggle="modal"
data-bs-target="#exampleModal"
@click="buyStock(stock)"
>
Activate Modal
</button>
<modal :modalTitle="stock['name']" />
I do have props on the both components我在这两个组件上都有道具
The problem is with the way modal was used.问题在于模态的使用方式。
Generally, bootstrap modal is opened using data-bs-toggle="modal" and data-bs-target="modalInfo"
attributes.通常,使用
data-bs-toggle="modal" and data-bs-target="modalInfo"
属性打开引导模式。 data-bs-target
is connected with id="modalInfo"
in order to open and close the model. data-bs-target
与id="modalInfo"
连接以打开和关闭 model。
In your case, for all three has the same data-bs-target and id, hence it was showing the same first modal in all the cases.在您的情况下,对于所有三个具有相同的 data-bs-target 和 id,因此它在所有情况下都显示相同的第一个模态。
Here is the working example: Codesandbox这是工作示例: Codesandbox
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.