詳解使用element-ui table組件的篩選功能的一個(gè)小坑
使用element-ui table組件的篩選功能的一個(gè)小坑
使用自定義模板和篩選功能,一開始的代碼
<el-table-column v-if="key==='isShow'" label="是否在發(fā)現(xiàn)頁展示" :filters="[{text:'已展示',value: true},{text: '未展示', value: false}]" :filter-method="filterShow">
<template slot-scope="scope">
<el-tag type="success" v-if="scope.row.isShow">顯示</el-tag>
<el-tag type="danger" v-else>不顯示</el-tag>
</template>
</el-table-column>
<el-table-column v-else-if="key==='isHandle'" label="是否已經(jīng)審核" :filters="[{text:'已處理',value: true},{text: '未處理', value: false}]" :filter-method="filterHandle">
<template slot-scope="scope">
<el-tag type="info" v-if="scope.row.isHandle">已處理</el-tag>
<el-tag type="warning" v-else>未處理</el-tag>
</template>
</el-table-column>
然后發(fā)現(xiàn)篩選功能怎么都不能實(shí)現(xiàn),上網(wǎng)查找原因才發(fā)現(xiàn),雖然官網(wǎng)在寫自定義模板的示例代碼時(shí)是這樣的:
<template>
<el-table
:data="tableData"
style="width: 100%">
<el-table-column
label="日期"
width="180">
<template slot-scope="scope">
<i class="el-icon-time"></i>
<span style="margin-left: 10px">{{ scope.row.date }}</span>
</template>
</el-table-column>
<el-table-column
label="姓名"
width="180">
<template slot-scope="scope">
<el-popover trigger="hover" placement="top">
<p>姓名: {{ scope.row.name }}</p>
<p>住址: {{ scope.row.address }}</p>
<div slot="reference" class="name-wrapper">
<el-tag size="medium">{{ scope.row.name }}</el-tag>
</div>
</el-popover>
</template>
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button
size="mini"
@click="handleEdit(scope.$index, scope.row)">編輯</el-button>
<el-button
size="mini"
type="danger"
@click="handleDelete(scope.$index, scope.row)">刪除</el-button>
</template>
</el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [{
date: '2016-05-02',
name: '王小虎',
address: '上海市普陀區(qū)金沙江路 1518 弄'
}, {
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀區(qū)金沙江路 1517 弄'
}, {
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀區(qū)金沙江路 1519 弄'
}, {
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀區(qū)金沙江路 1516 弄'
}]
}
},
methods: {
handleEdit(index, row) {
console.log(index, row);
},
handleDelete(index, row) {
console.log(index, row);
}
}
}
</script>
就是使用scope代替了prop,就是沒有加上prop。
這就是坑所在地方,element的內(nèi)部使用篩選功能時(shí)應(yīng)該是使用到了prop,所以加上prop之后篩選功能就可以用了:
<el-table-column v-if="key==='isShow'" label="是否在發(fā)現(xiàn)頁展示" prop="isShow" :filters="[{text:'已展示',value: true},{text: '未展示', value: false}]" :filter-method="filterShow">
<template slot-scope="scope">
<el-tag type="success" v-if="scope.row.isShow">顯示</el-tag>
<el-tag type="danger" v-else>不顯示</el-tag>
</template>
</el-table-column>
<el-table-column v-else-if="key==='isHandle'" label="是否已經(jīng)審核" prop="isHandle" :filters="[{text:'已處理',value: true},{text: '未處理', value: false}]" :filter-method="filterHandle">
<template slot-scope="scope">
<el-tag type="info" v-if="scope.row.isHandle">已處理</el-tag>
<el-tag type="warning" v-else>未處理</el-tag>
</template>
</el-table-column>
使用elementUi 的table組件的篩選功能記得加prop!!!
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue3.x使用swiper實(shí)現(xiàn)卡片輪播
這篇文章主要為大家詳細(xì)介紹了vue3.x使用swiper實(shí)現(xiàn)卡片輪播,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07
el-table表頭根據(jù)內(nèi)容自適應(yīng)完美解決表頭錯(cuò)位和固定列錯(cuò)位
這篇文章主要介紹了el-table表頭根據(jù)內(nèi)容自適應(yīng)完美解決表頭錯(cuò)位和固定列錯(cuò)位,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01
vue實(shí)現(xiàn)可移動(dòng)的懸浮按鈕
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)可移動(dòng)的懸浮按鈕,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-03-03
Vuex如何獲取getter對(duì)象中的值(包括module中的getter)
這篇文章主要介紹了Vuex如何獲取getter對(duì)象中的值(包括module中的getter),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
uni-app無限級(jí)樹形組件簡單實(shí)現(xiàn)代碼
文章介紹了如何在uni-app中簡單封裝一個(gè)無限級(jí)樹形組件,該組件可以無線嵌套,展開和收縮,并獲取子節(jié)點(diǎn)數(shù)據(jù),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧2025-01-01

