element-ui el-table表格展开行 对当前行操作,当前行默认展开

点击上下架状态但是展开行依旧是展开的                                                                          

 <el-table :data="shopData" 
             border 
             style="width: 100%" 
            :row-key="getRowKeys" 
            :expand-row-keys="expands">
              <el-table-column type="expand" >
           <template slot-scope="props">
  getRowKeys(row) {
        return row.infoId
      },//当前行的唯一标识

页面初始化展开某一行的话

mounted(){
 this.expands.push(this.dataList[0].infoId)
}

 

 handleStatusChange(row) {
     // return
      console.log(row,'2223');
      ('确认要' + text+ '商品')
      let text = row.status === 0 ? "下架" : "上架";
      this.$modal
        .confirm('确认要"' + text + '"该商品吗?')
        .then(function () {
          // 调用 商品 上下架 接口,
          return statusEditor({
           // productId : row.productId,
           // stationId: row.stationId,
           // modelId:row.modelId,
            mid:row.mid,
            status:row.status,
          });
        })
        .then(() => {
          this.$modal.msgSuccess(text + "成功");
          this.loadProduct();
          this.expands.push(this.dataList[0].infoId)//当前行id 放入
        })
        .catch(function () {
          row.status = row.status === 0 ? 1 : 0;
        });
    },

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Element UI中,要展开`el-table`表格,你可以使用`expand-row-keys`属性来控制展开。首先,你需要在表格的数据中添加一个属性用于标识是否展开,比如命名为`expanded`。然后,在`el-table`组件上添加`expand-row-keys`属性,并将其绑定到一个数组,用于存储展开的唯一标识。最后,在表格的列配置中,使用`scoped-slot`来自定义展开的内容。 下面是一个示例代码: ```html <template> <el-table :data="tableData" :expand-row-keys="expandedRows" @expand-change="handleExpandChange" > <!-- 自定义展开内容 --> <template v-slot="{ row }"> <el-form :inline="true"> <el-form-item label="姓名"> {{ row.name }} </el-form-item> <el-form-item label="年龄"> {{ row.age }} </el-form-item> <!-- 其他表单项 --> </el-form> </template> <!-- 表格列配置 --> <el-table-column prop="name" label="姓名"></el-table-column> <el-table-column prop="age" label="年龄"></el-table-column> <!-- 其他列配置 --> </el-table> </template> <script> export default { data() { return { tableData: [ { name: '张三', age: 18, expanded: false }, { name: '李四', age: 20, expanded: false }, // 其他数据 ], expandedRows: [] // 存储展开的唯一标识 }; }, methods: { handleExpandChange(row, expanded) { // 当展开变化时更新expandedRows数组 if (expanded) { this.expandedRows.push(row); // 将展开添加到数组中 } else { const index = this.expandedRows.findIndex(item => item === row); if (index > -1) { this.expandedRows.splice(index, 1); // 从数组中移除收起的 } } } } }; </script> ``` 这是一个基本的示例,你可以根据你的实际需求自定义展开内容和其他列配置。请注意,你需要根据实际情况修改表格数据和列配置的属性名。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值