亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

具有 Vue(2) 綁定的 HTML 表格行

具有 Vue(2) 綁定的 HTML 表格行

呼喚遠方 2023-08-18 13:53:01
我有一個購物車/訂單列表,我將其綁定到一個工作正常的數組。我最近為添加到數組中的每個項目添加了一個行號,還有一個按鈕行。問題是我將它們綁定到當前行,如下所示<div id="table">    <table class="table table-sm table-bordered table-striped">      <thead class="thead-dark">        <tr>          <th scope="col">#</th>          <th scope="col">Product</th>          <th scope="col">Type</th>          <th scope="col">Attribute</th>          <th scope="col">Height</th>          <th scope="col">Width</th>          <th scope="col">Price</th>          <th width="1%" scope="col">Remove</th>        </tr>      </thead>        <tbody>          <tr v-for="(item, index) in table_products">            <td>{{ index +1 }}</td>            <td>{{ item.product }}</td>            <td>{{ item.type }}</td>            <td>{{ item.attribute }}</td>            <td>{{ item.height }}</td>            <td>{{ item.width }}</td>            <td>{{ item.price }}</td>            <td><button class="btn btn-danger" @click="deleteRow(index)">X</button></td>          </tr>         </tbody>      </table>    </div>  </div>我從來沒有遇到過問題,因為綁定項值為空,因此從未創建該行。但現在索引和按鈕創建表的第一行。有沒有辦法可以在頁面加載時清除數組,或者我是否以錯誤的方式進行操作?
查看完整描述

1 回答

?
梵蒂岡之花

TA貢獻1900條經驗 獲得超5個贊

我初始化 table_products [{}]而不是[]

從初始化開始,它在數組中有一個空對象,因此它有一個元素。初始化一個空數組解決了這個問題,因為它沒有元素。


查看完整回答
反對 回復 2023-08-18
  • 1 回答
  • 0 關注
  • 119 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號