如何获取行内数据

vue提供了获取行内数据的方法,也就是通过slot插槽区获取当前行内数据以下是vue2,vue3中获取行内数据的方式

  • <el-table max-height="290" :data="userTableData" border style="width: 100%">
    	  <el-table-column label="名字">
    		    <template slot-scope="scope">
                    //通过slot.scope获取当前作用域插槽数据
    		      {{scope.row.name}}
                  {{scope.row.age}}
    				//获取当前行的索引值
    			  {{scope.$index+1}}
    		    </template>
    </el-table>
    
  • 在element库中对此做了一些改变

  • 直接在#default=scope即可获取对应行的数据

      <el-table-column
        v-for="item in tableLabel"
        :key="item.prop"
        :label="item.label"
        :prop="item.prop"
        :width="item.width ? item.width : 280"
      />
      <el-table-column fixed="right" label="操作" min-width="160">
          //直接在#default=scope即可获取对应行的数据
          //也可以通过解构获取某个特定数据比如 #default = {row}
        <template #default="scope">
          <el-button size="small" @click="EditUser(scope.row)">编辑</el-button>
          <el-button type="danger" size="small" @click="removeUser(scope.row)"
            >删除</el-button
    		>
        </template>
      </el-table-column>
    

在element中针对还设置了去许多方法与事件用与table表单,比如设置:垂直滚动距离setScrollTop,row-click行点击事件,cell-click单元格点击事件等等,elementUI官网做了详细说明

posted @ 2022-10-25 22:22  YYYang333  阅读(81)  评论(0)    收藏  举报