vue.js - 如何使用 vuejs 数据属性作为 html 属性
问题描述
我正在尝试使用循环中的卡片组件在 vuejs 中使用引导程序创建手风琴。我想使用命令变量的 id 属性,以便每张卡片都有它的 id,这样当我们点击一张卡片时,只有这张卡片会打开,而不是所有卡片。这是我的代码:
<div id="accordion">
<div class="card" v-for="commande in commandes.data" :key="commande.id">
<div class="card-header" :id="commande.id">
<h3 class="card-title">
<button class="btn btn-link col-md-12" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<div class="text-primary">{{commande.id}}</div>
</button>
</h3>
</div>
<!-- /.card-header -->
<div id="collapseOne" class="collapse show" :aria-labelledby="commande.id" data-parent="#accordion">
<div class="card-body table-responsive p-0">
<table class="table table-hover">
<tbody>
<tr v-for="(produit, index) in commande.produits" :key="index">
<td>{{produit.designation}}</td>
<td>{{produit.prix_vente}}</td>
<td>{{produit.pivot.quantite}}</td>
<td>{{produit.prix_vente*produit.pivot.quantite}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- /.card-body -->
<div class="card-footer">
<pagination :data="commandes" @pagination-change-page="getResults"></pagination>
</div>
</div>
</div>
但是当我点击一张卡片时,所有其他卡片都会打开。这似乎是由于标签的data-target
属性和包含的标签。我不能在属性中放置变量。如何解决这个问题?<button>
card-header
attribute id
<div>
card-body
data-target
解决方案
如果你想使用 Vue 数据属性作为 HTML Attribute,只需在它前面加上一个“:”即可。
<div :id="name_of_data_property">
推荐阅读
- hadoop - HDFS 复制
- android - 如何在 TextInputLayout 内定位 imageButton
- python-3.x - 使用 google api 创建和共享电子表格
- laravel - GroupBy 关于 Eloquent 关系
- javafx - JavaFX PasswordField echo char 在不同的计算机上不同
- c - 如何在C中的同一行中扫描字符串(带空格)和整数
- wordpress - wordpress 注入脚本和图像查找
- mqtt - 为什么 MQTT 被 Keep-Alive 断开连接?
- regex - 使用python中的正则表达式从html标签获取日期
- circleci - Bitbucket-pipelines 到 circleCI 的翻译