關(guān)于el-table表格組件中插槽scope.row的使用方式
el-table表格組件中插槽scope.row使用
要實(shí)現(xiàn)點(diǎn)擊查看顯示后端返回的字段并以文字渲染到頁(yè)面上,就要是使用到插槽
下圖是要實(shí)現(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>
//給學(xué)歷定義一個(gè)edutype方法,通過(guò)scope.row傳參
<div class="heighth">
學(xué)歷:<span>{{ edutype(scope.row.education) }}</span>
</div>
<div class="heighth">
專業(yè):<span>{{ scope.row.major }}</span>
</div>
<div class="heighth">
技能及經(jīng)驗(yàn):<span>{{ scope.row.experience_skills }}</span>
</div>
</div>
<el-button slot="reference" type="text">查看</el-button>
</el-popover>
</template>
</el-table-column>
methods: {
//通過(guò)row接受參數(shù)
edutype(row) {
// console.log(row);
if (row == "primary school") {
return "小學(xué)";
}
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 "不限";
}
}
}
這樣就實(shí)現(xiàn)啦。。。。。
slot-scope和scope.row的用法
實(shí)現(xiàn)效果
根據(jù)后端傳來(lái)的mg_state的bool型數(shù)據(jù)來(lái)渲染開關(guān)狀態(tài),當(dāng)為true時(shí),開關(guān)打開;為false時(shí)關(guān)閉
解決
狀態(tài)開關(guān)屬于單元格,也屬于一行,如果我們拿到這一行的數(shù)據(jù),就可以.mg_state具體值,則可以按需渲染效果。所以想到用作用域插槽來(lái)渲染狀態(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”
- 表格綁定了用于存儲(chǔ)數(shù)據(jù)的數(shù)組,里面每一個(gè)元素都是數(shù)據(jù)對(duì)象
- 首先在狀態(tài)這一列中定義了一個(gè)作用域插槽
- 通過(guò)slot-scope="scope"來(lái)接收作用域插槽的數(shù)據(jù)(添加屬性slot-scope,并且定義對(duì)象scope)
- scope.row
- scope有一個(gè)屬性row(ElementUI文檔),scope.row可以拿到對(duì)應(yīng)行的數(shù)據(jù)
- v-model=“scope.row.mg_state”
- 需要把這個(gè)開關(guān)的狀態(tài)綁定到scope.row.mg_state屬性上
ElementUI文檔

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

效果

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue element ui使用選擇器實(shí)現(xiàn)地區(qū)選擇兩種方法
這篇文章主要給大家介紹了關(guān)于vue element ui使用選擇器實(shí)現(xiàn)地區(qū)選擇的兩種方法,Element UI是一套基于Vue.js開發(fā)的UI組件庫(kù),其中包含了地區(qū)選擇器(Cascader)組件,需要的朋友可以參考下2023-09-09
vue element 關(guān)閉當(dāng)前tab 跳轉(zhuǎn)到上一路由操作
這篇文章主要介紹了vue element 關(guān)閉當(dāng)前tab 跳轉(zhuǎn)到上一路由操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-07-07
解決Echarts2豎直datazoom滑動(dòng)后顯示數(shù)據(jù)不全的問(wèn)題
這篇文章主要介紹了解決Echarts2豎直datazoom滑動(dòng)后顯示數(shù)據(jù)不全的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-07-07
vue使用iview的modal彈窗嵌套modal出現(xiàn)格式錯(cuò)誤的解決
這篇文章主要介紹了vue使用iview的modal彈窗嵌套modal出現(xiàn)格式錯(cuò)誤的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09
Vue3使用Lottie實(shí)現(xiàn)一個(gè)簡(jiǎn)單的加載動(dòng)畫
Lottie 是一個(gè)流行的動(dòng)畫庫(kù),它允許我們使用 JSON 文件來(lái)渲染高質(zhì)量的動(dòng)畫,本文將介紹一下如何在Vue3中集成 Lottie 動(dòng)畫實(shí)現(xiàn)一個(gè)加載動(dòng)畫效果,需要的可以了解下2025-02-02
vite如何build時(shí)清除console.log()問(wèn)題
這篇文章主要介紹了vite如何build時(shí)清除console.log()問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07
vue創(chuàng)建項(xiàng)目卡住不動(dòng),vue?create?project卡住不動(dòng)的解決
這篇文章主要介紹了vue創(chuàng)建項(xiàng)目卡住不動(dòng),vue?create?project卡住不動(dòng)的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10
vue + element-ui的分頁(yè)問(wèn)題實(shí)現(xiàn)
這篇文章主要介紹了vue + element-ui的分頁(yè)問(wèn)題實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-12-12

