列表html代码
这里需要注意的是el-table一定要有ref属性,比如ref=“table”
<div style="padding:0 1%;">
<el-table :data="lists" v-loading="loading" ref="table" tooltip-effect="dark" @selection-change="handleSelectionChange" :height="height-220" border align="center">
<el-table-column
type="selection"
:width="width*0.05">
</el-table-column>
<el-table-column type=index label="序号" :index="typeIndex" :width="width*0.05" align="center"></el-table-column>
<el-table-column prop="picimg" label="图片" :width="width*0.25" align="center">
<template slot-scope="scope">
<img :src="scope.row.picimg" alt="" style="width: 100px;height:50px">
</template>
</el-table-column>
<el-table-column prop="title" label="产品简称" :width="width*0.25" align="center"></el-table-column>
<el-table-column prop="depict" label="产品描述" :width="width*0.25" align="center"></el-table-column>
<el-table-column prop="picimg" label="图片" :width="width*0.25" align="center">
<template slot-scope="scope">
<img :src="scope.row.picimg" alt="" style="width: 100px;height:50px">
</template>
</el-table-column>
</el-table>
</div>
methods中的代码
请求完列表后进行回调操作,this.$refs.table.toggleRowSelection(this.lists[i],true) 是官网中给出的方法,第一个参数是需要被勾选的行组成的列表,第二个参数为true,必须要传。
getList(){
let data={
pageModel:{
pageNo:this.pageNo,
pageSize:this.limit
},
shop:{
style:this.radio
}
}
listShop(data).then(res =>{
this.total = res.data.data.total
this.lists = res.data.data.rows.filter(res=>{
return res.isdelete == '0'
})
})
//请求完列表后,回调,过滤需要被勾选的
.then(()=>{
for(let i=0;i<this.lists.length;i++){
if(this.lists[i].style == this.radio){
this.$refs.table.toggleRowSelection(this.lists[i],true);
}
}
})
},