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中遍历是
  • {{s.name}}

  • 注意看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)">removebutton>
						<button type="button" @click="update(s,index)">update button>
					td>
				tr>
  • 现在element组件中
    所以 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>

谢谢!

你可能感兴趣的:(前端)