viewDesign里的table内嵌套select动态添加表格行绑定内容丢失

问题

描述

viewDesign里的table内嵌套select,表格的行数是手动点击按钮添加的,添加第一行选择select的内容能正常展示,添加第二行第一行的select的内容消失

代码

复制代码
<FormItem label="内饰颜色">
              <Table
                class="mt_10"
                border
                :columns="brandColumns"
                :data="brandData"
                ref="table"
                style="width:700px"
              >
                <template slot="brandListSlot" slot-scope="{ row,index }">
                  <Select :key="row.id" ref="selects"  placeholder="输入关键字进行选择" v-model="row.brandId" filterable :loading="loading2" clearable
                  :remote-method="remoteMethod1" >
                          <Option v-for="item in brandSelectList" :key="item.id" :label="item.name ? item.name : ''" :value="item.id">
                          </Option>
                  </Select>
                </template>
              </Table>
              <Button class="appendBtn" type="info" @click="appendRow">添加一行</Button>
            </FormItem>

解决

复制代码
<FormItem label="内饰颜色">
              <Table
                class="mt_10"
                border
                :columns="brandColumns"
                :data="brandData"
                ref="table"
                style="width:700px"
              >
                <template slot="brandListSlot" slot-scope="{ row,index }">
                  <Select :key="row.id" ref="selects"  placeholder="输入关键字进行选择" v-model="brandData[index].brandId" filterable :loading="loading2" clearable
                  :remote-method="remoteMethod1" >
                          <Option v-for="item in brandSelectList" :key="item.id" :label="item.name ? item.name : ''" :value="item.id">
                          </Option>
                  </Select>
                </template>
              </Table>
              <Button class="appendBtn" type="info" @click="appendRow">添加一行</Button>
            </FormItem>

分析

  • 直接绑定到 brandData[index].brandId 确保数据源始终是响应式的,避免中间对象(如 row)可能存在的引用问题。

  • 避免响应式数据丢失问题(直接操作数组元素时,Vue 2.x 可能无法检测变化)。

  • 通过 index 精准定位数据源,确保每行的 Select 独立管理自己的 brandId

相关推荐
李广坤9 小时前
MySQL 大表字段变更实践(改名 + 改类型 + 改长度)
数据库
Turnip12021 天前
深度解析:为什么简单的数据库"写操作"会在 MySQL 中卡住?
后端·mysql
爱可生开源社区1 天前
2026 年,优秀的 DBA 需要具备哪些素质?
数据库·人工智能·dba
随逸1772 天前
《从零搭建NestJS项目》
数据库·typescript
加号32 天前
windows系统下mysql多源数据库同步部署
数据库·windows·mysql
シ風箏2 天前
MySQL【部署 04】Docker部署 MySQL8.0.32 版本(网盘镜像及启动命令分享)
数据库·mysql·docker
李慕婉学姐2 天前
Springboot智慧社区系统设计与开发6n99s526(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
数据库·spring boot·后端
百锦再2 天前
Django实现接口token检测的实现方案
数据库·python·django·sqlite·flask·fastapi·pip
WeiXin_DZbishe2 天前
基于django在线音乐数据采集的设计与实现-计算机毕设 附源码 22647
javascript·spring boot·mysql·django·node.js·php·html5
tryCbest2 天前
数据库SQL学习
数据库·sql