首先要在表格里添加 :row-class-name=“rowClassName”

 <el-table
    :data="tableData"
    ref="multipleTable"
    :row-class-name="rowClassName"
    border
  >
    <el-table-column prop="name4" label="所属部门"></el-table-column>
    <el-table-column  label="操作">
      <template #default="scope">
        <el-button type="text" size="medium" @click="update(scope.row)">修改</el-button>
      </template>
    </el-table-column>
  </el-table>
  export default {
		data(){
			return{
				tableData:[],
			}
		},
		methods:{
			 rowClassName({row, rowIndex}) {
		      //把每一行的索引放进row
		       row.index = rowIndex;
		    },
		    update(id,row){
		      this.$nextTick(() => {
		        setTimeout(()=>{
		          console.log(row.index);
		          this.addyg=true
		          this.tianjia=this.tableData[row.index]
		        },100)
		      })
		    },
		}
  }
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐