2020-08-21随笔集el-table表格中的select数据只作用于当前行

Element el-table中插入select下拉框 (每行数据只作用于当前行)


简介:
项目中遇到了这个问题,因为之前没有碰到过这种功能问题,所以一时间页无从下手,在网上搜了很多,可能是因为自己马虎或者没有仔细看,漏掉了很多细节,下面话不多说上代码

<el-table-column label="领域" align="center">
  <template slot-scope="scope">
      <el-select
        v-model="scope.row.categoryname"
        @change="changecategoryname(scope.row, scope.$index)"
        size="small"
      >
        <el-option
          v-for="item in list_firstmodule"
          :label="item.realname"
          :value="item.id"
          :key="item.id"
        ></el-option>
      </el-select>
  </template>
</el-table-column>
<el-table-column label="项目" align="center">
  <template slot-scope="scope">
    <el-select
      v-model="scope.row.parentprojectname"
      style="width:150px"
      @change="superprojectversion"
      size="small"
    >
      <el-option
        v-for="item in scope.row.list_super"
        :label="item.projectname"
        :value="item.id"
        :key="item.id"
      ></el-option>
    </el-select>
  </template>
</el-table-column>

说明:
因为项目需求,我需要根据领域的选值来获取项目的值
如果是其他模块,一样的道理,这样做就对了~

上面的html代码没什么重点,主要是change事件需要传scope.row & scope.$index,另外下面的(不限于)项目模块遍历的值需要加上scope.row,其实就是把被遍历的数组变成了tabledata的值(下面会说明)

methods:

// 领域模块change获取项目模块的值
changecategoryname (row, index) {
      let modules = row.categoryname
      let supers = row.parentprojectname
      this.$api.get("url", 
   		{
          params: {
            key: supers,
            category: modules,
        },
      }).then((res) => {
          if (res.status == 200) {
            this.list_super = res.data.data.data || [];
            this.$set(this.tablelist[index],'list_super', this.list_super);
          }
      });
    },

change事件方法,用到$set方法
可点击 vue使用set方法查看set具体使用方法

回归正题, 上面的方法中主要是最后一句,通过set方法使原本的table表格data数据添加"list_super"这一组数据,再联系上面的scope.row.list_super说明这种方法是把获取到的数据添加到data数据中,小白个人理解,如有问题请各位大佬多多指教~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值