element组件中table中数据遍历的索引和单个对象

给你的按钮标签上加上以下代码

nodejs中element组件中遍历时候的索引及对象。

scope.row代表当前遍历的子对象,scope.$index代表遍历时索引

<template slot-scope="scope">
        <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
        <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>

scope.$index表示当前对象的索引
scope.row表示当前遍历的子对象

  • 原本vue中遍历是<li v-for="s in stus">{{s.name}}</li>
    注意看v-for="(s,index) in stus,s代表当前遍历的子对象,index代表遍历时索引
<tr height="50px" v-for="(s,index) in stus">
					<td>{{index+1}}</td>
					<td>{{s.id}}</td>
					<td>{{s.name}}</td>
					<td>{{s.sex}}</td>
					<td>{{s.hobbies}}</td>
					<td>{{s.adress}}</td>
					<td>{{s.beizhu}}</td>
					<td><button type="button" @click="remove(index)">remove</button>
						<button type="button" @click="update(s,index)">update </button>
					</td>
				</tr>
  • 现在element组件中<el-table :data="users" style="width: 100%"></>
    所以 scope.row代表当前遍历的子对象,scope.$index代表遍历时索引
<div class="grid-content bg-purple-light">
	<el-table :data="stus" style="width: 100%;height: 450px; overflow-y: scroll;" >
		<el-table-column prop="id" label="序号" width="80"></el-table-column>
		<el-table-column prop="id" label="学号" width="80"></el-table-column>
		<el-table-column prop="name" label="姓名" width="80"></el-table-column>
		<el-table-column prop="sex" label="性别" width="80"></el-table-column>
		<el-table-column prop="hobbies" label="爱好"></el-table-column>
		<el-table-column prop="adress" label="籍贯"></el-table-column>
		<el-table-column prop="beizhu" label="备注"></el-table-column>
		<el-table-column prop="beizhu1" label="操作">
		<template slot-scope="scope">
			<el-button type="primary" @click="update(scope.row,scope.$index)">修改</el-button>
		</template>
		</el-table-column>
	</el-table>
</div>

谢谢!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值