el-table表格组件中插槽scope.row如何使用(el-table,scope.row,开发技术)

时间:2024-05-06 16:07:30 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

接下来,请跟着小编一起来学习吧!

el-table表格组件中插槽scope.row使用

要实现点击查看显示后端返回的字段并以文字渲染到页面上,就要是使用到插槽

下图是要实现的:

el-table表格组件中插槽scope.row如何使用

<el-table-columnlabel="任职要求"width="100"align="center">
<templateslot-scope="scope">
<el-popoverplacement="bottom"width="300"trigger="click">
<div>
<divclass="line">任职要求</div>
<divclass="heighth">
工作年限:<span>{{scope.row.worked_year}}</span>
</div>
//给学历定义一个edutype方法,通过scope.row传参
<divclass="heighth">
学历:<span>{{edutype(scope.row.education)}}</span>
</div>
<divclass="heighth">
专业:<span>{{scope.row.major}}</span>
</div>
<divclass="heighth">
技能及经验:<span>{{scope.row.experience_skills}}</span>
</div>
</div>
<el-buttonslot="reference"type="text">查看</el-button>
</el-popover>
</template>
</el-table-column>
methods:{
//通过row接受参数
edutype(row){
//console.log(row);
if(row=="primaryschool"){
return"小学";
}
if(row=="juniorhighschool"){
return"初中";
}
if(row=="seniorhighschool"){
return"高中";
}
if(row=="technicalsecondaryschool"){
return"中专";
}
if(row=="juniorcollege"){
return"大专";
}
if(row=="undergraduate"){
return"本科";
}
if(row=="graduatestudent"){
return"研究生";
}
if(row=="unlimited"){
return"不限";
}
}
}

这样就实现啦。。。。。

slot-scope和scope.row的用法

实现效果

根据后端传来的mg_state的bool型数据来渲染开关状态,当为true时,开关打开;为false时关闭

解决

状态开关属于单元格,也属于一行,如果我们拿到这一行的数据,就可以.mg_state具体值,则可以按需渲染效果。所以想到用作用域插槽来渲染状态这一列

<el-table:data="userlist"borderstripe>
<el-table-columntype="index"></el-table-column>
<el-table-columnlabel="姓名"prop="username"></el-table-column>
<el-table-columnlabel="邮箱"prop="email"></el-table-column>
<el-table-columnlabel="电话"prop="mobile"></el-table-column>
<el-table-columnlabel="角色"prop="role_name"></el-table-column>
<el-table-columnlabel="状态">
<templateslot-scope="scope">
<el-switchv-model="scope.row.mg_state"></el-switch>
</template>
</el-table-column>
<el-table-columnlabel="操作"></el-table-column>
</el-table>
  • data=“userList”

  • 表格绑定了用于存储数据的数组,里面每一个元素都是数据对象

  • 首先在状态这一列中定义了一个作用域插槽

  • 通过slot-scope="scope"来接收作用域插槽的数据(添加属性slot-scope,并且定义对象scope)

  • scope.row

  • scope有一个属性row(ElementUI文档),scope.row可以拿到对应行的数据

  • v-model=“scope.row.mg_state”

  • 需要把这个开关的状态绑定到scope.row.mg_state属性上

ElementUI文档

el-table表格组件中插槽scope.row如何使用

userList数据如下:

el-table表格组件中插槽scope.row如何使用

效果

el-table表格组件中插槽scope.row如何使用

若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

本文:el-table表格组件中插槽scope.row如何使用的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:windows server 2016怎么搭建FTP服务器下一篇:

10 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18