el-table默认选中高亮第一行,clearble触发事件_el-table默认选中第一行_小青龙Zack.ming
?页面大概长这个样子,各位只参考用到的部分即可。
<div class="query_rule">
? ? ? ? ? ? ? ? ? ? <span class="lable_title">规则名称</span>
? ? ? ? ? ? ? ? ? ? <el-input class="query_value" v-model.trim="queryParams.value" clearable @clear="getTableList()"></el-input>
? ? ? ? ? ? ? ? ? ? <el-button @click="getTableList()">查询</el-button>
? ? ? ? ? ? ? ? ? ? <el-button style="float:right;" type="text" @click="addNewObj">添加</el-button>
? ? ? ? ? ? ? ? </div>
当input框添加clearable属性后,即可通过@clear触发-点击清除图标后的回调事件-
<el-table :data="tableData" style="width:100%;margin-top:20px;min-height:700px;" border highlight-current-row @row-click="rowTriggerFn" ref="inRuTabRef">
? ? ? ? ? ? ? ? ? ? <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
? ? ? ? ? ? ? ? ? ? <el-table-column prop="name" label="规则名称" align="center" show-overflow-tooltip></el-table-column>
? ? ? ? ? ? ? ? ? ? <el-table-column prop="founder" label="创建人" align="center" show-overflow-tooltip></el-table-column>
? ? ? ? ? ? ? ? ? ? <el-table-column prop="createUser" label="创建用户" align="center" show-overflow-tooltip></el-table-column>
? ? ? ? ? ? ? ? ? ? <el-table-column prop="time" label="创建时间" align="center" show-overflow-tooltip></el-table-column>
? ? ? ? ? ? ? ? ? ? <el-table-column label="操作" align="center" width="180">
? ? ? ? ? ? ? ? ? ? ? ? <template slot-scope="scope">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <el-button type="text" @click.stop="editTableItem(scope.row)">编辑</el-button>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <el-button type="text" style="color:red;" @click.stop="delTableItem(scope.row.id)">删除</el-button>
? ? ? ? ? ? ? ? ? ? ? ? </template>
? ? ? ? ? ? ? ? ? ? </el-table-column>
? ? ? ? ? ? ? ? </el-table>
在el-table中,highlight-current-row属性高亮选中行,@row-click回调点击表格行事件,在编辑及删除时记得加上.stop事件修饰符,阻止冒泡事件,防止不必要的联动;
rowTriggerFn(row){
? ? ? ? ? ? console.log(row);
? ? ? ? },
getTableList(){
? ? ? ? ? ? getlist(this.queryParams).then(res=>{
? ? ? ? ? ? ? ? // console.log(res);
? ? ? ? ? ? ? ? if(res.status==200){
? ? ? ? ? ? ? ? ? ? this.tableData=res.data.data.inspectionRules;
? ? ? ? ? ? ? ? ? ? this.total=res.data.data.rows;
? ? ? ? ? ? ? ? ? ? this.$nextTick(()=>{
? ? ? ? ? ? ? ? ? ? ? ? this.$refs.inRuTabRef.setCurrentRow(this.tableData[0]);
? ? ? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }).catch(err=>{
? ? ? ? ? ? ? ? console.log(err);
? ? ? ? ? ? })
? ? ? ? },
在getTableList事件中的getlist是我引入的接口封装,各位可以忽略,默认高亮主要用到的是setCurrentRow;ref属性相当于给dom起了一个name,通过refs使用后,引用setCurrentRow(table[index])即可;
相关文章
- ORA-00904:标识符无效(太坑了!!)_不会秃头的_图图_ora-00904
- java 根据时间筛选查询_AD_youyu_java根据时间段查询数据
- SQL注入_枫雨梦_sql注入
- 【SQL】SQL的基础语法_和风与影_sql语法
- MySQL核心SQL:结构化查询语句SQL、库操作、表操作、CRUD__索伦_sql数据库
- DENSE_RANK函数_四问四不知_dense_rank()
- spring中遇到的java.lang.ClassCastException中cannot be cast to报错(初学)_bp粉
- HBase基础【HBase简介、HBase安装、HBase shell操作】_hike76_hbase
- SAS笔记#SAS中的SQL语言_OZ的学习馆_sas sql
- sql如何根据时间取出最新的数据记录_Bingo_BIG_sql 获取最新数据
- Mysql中查询语句的执行顺序_mysnsds_mysql语句执行顺序
- 中高级Java程序员,你不得不掌握的基本功,挑战20k+_m0_67401499
- SQL 事务_平凡存在_sql事务
- mysql的DML进阶,分页查找,SQL约束,多表操作学习_小杰312
- 【SQL SERVER】递归查询_MoFe1_sqlserver 递归查询
- nacos配置中心_Qiumin~_nacos配置中心配置