關(guān)于el-table表格組件中插槽scope.row的使用方式
el-table表格組件中插槽scope.row使用
要實現(xiàn)點擊查看顯示后端返回的字段并以文字渲染到頁面上,就要是使用到插槽
下圖是要實現(xiàn)的

<el-table-column label="任職要求" width="100" align="center">
<template slot-scope="scope">
<el-popover placement="bottom" width="300" trigger="click">
<div>
<div class="line">任職要求</div>
<div class="heighth">
工作年限:<span>{{ scope.row.worked_year }}</span>
</div>
//給學歷定義一個edutype方法,通過scope.row傳參
<div class="heighth">
學歷:<span>{{ edutype(scope.row.education) }}</span>
</div>
<div class="heighth">
專業(yè):<span>{{ scope.row.major }}</span>
</div>
<div class="heighth">
技能及經(jīng)驗:<span>{{ scope.row.experience_skills }}</span>
</div>
</div>
<el-button slot="reference" type="text">查看</el-button>
</el-popover>
</template>
</el-table-column>
methods: {
//通過row接受參數(shù)
edutype(row) {
// console.log(row);
if (row == "primary school") {
return "小學";
}
if (row == "junior high school") {
return "初中";
}
if (row == "senior high school") {
return "高中";
}
if (row == "technical secondary school") {
return "中專";
}
if (row == "junior college") {
return "大專";
}
if (row == "undergraduate") {
return "本科";
}
if (row == "graduate student") {
return "研究生";
}
if (row == "unlimited") {
return "不限";
}
}
}
這樣就實現(xiàn)啦。。。。。
slot-scope和scope.row的用法
實現(xiàn)效果
根據(jù)后端傳來的mg_state的bool型數(shù)據(jù)來渲染開關(guān)狀態(tài),當為true時,開關(guān)打開;為false時關(guān)閉
解決
狀態(tài)開關(guān)屬于單元格,也屬于一行,如果我們拿到這一行的數(shù)據(jù),就可以.mg_state具體值,則可以按需渲染效果。所以想到用作用域插槽來渲染狀態(tài)這一列
<el-table :data="userlist" border stripe>
<el-table-column type="index"></el-table-column>
<el-table-column label="姓名" prop="username"></el-table-column>
<el-table-column label="郵箱" prop="email"></el-table-column>
<el-table-column label="電話" prop="mobile"></el-table-column>
<el-table-column label="角色" prop="role_name"></el-table-column>
<el-table-column label="狀態(tài)" >
<template slot-scope="scope">
<el-switch v-model="scope.row.mg_state"></el-switch>
</template>
</el-table-column>
<el-table-column label="操作"> </el-table-column>
</el-table>
- data=“userList”
- 表格綁定了用于存儲數(shù)據(jù)的數(shù)組,里面每一個元素都是數(shù)據(jù)對象
- 首先在狀態(tài)這一列中定義了一個作用域插槽
- 通過slot-scope="scope"來接收作用域插槽的數(shù)據(jù)(添加屬性slot-scope,并且定義對象scope)
- scope.row
- scope有一個屬性row(ElementUI文檔),scope.row可以拿到對應行的數(shù)據(jù)
- v-model=“scope.row.mg_state”
- 需要把這個開關(guān)的狀態(tài)綁定到scope.row.mg_state屬性上
ElementUI文檔

userList數(shù)據(jù)如下:

效果

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue element ui使用選擇器實現(xiàn)地區(qū)選擇兩種方法
這篇文章主要給大家介紹了關(guān)于vue element ui使用選擇器實現(xiàn)地區(qū)選擇的兩種方法,Element UI是一套基于Vue.js開發(fā)的UI組件庫,其中包含了地區(qū)選擇器(Cascader)組件,需要的朋友可以參考下2023-09-09
vue element 關(guān)閉當前tab 跳轉(zhuǎn)到上一路由操作
這篇文章主要介紹了vue element 關(guān)閉當前tab 跳轉(zhuǎn)到上一路由操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07
解決Echarts2豎直datazoom滑動后顯示數(shù)據(jù)不全的問題
這篇文章主要介紹了解決Echarts2豎直datazoom滑動后顯示數(shù)據(jù)不全的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07
vue使用iview的modal彈窗嵌套modal出現(xiàn)格式錯誤的解決
這篇文章主要介紹了vue使用iview的modal彈窗嵌套modal出現(xiàn)格式錯誤的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09
vue創(chuàng)建項目卡住不動,vue?create?project卡住不動的解決
這篇文章主要介紹了vue創(chuàng)建項目卡住不動,vue?create?project卡住不動的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-10-10

