詳解使用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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue.js內(nèi)部自定義指令與全局自定義指令的實(shí)現(xiàn)詳解(利用directive)
這篇文章主要給大家介紹了關(guān)于vue.js內(nèi)部自定義指令與全局自定義指令的實(shí)現(xiàn)方法,vue.js中實(shí)現(xiàn)自定義指令的主要是利用directive,directive這個(gè)單詞是我們寫自定義指令的關(guān)鍵字,需要的朋友們下面跟著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-07-07
vue-router 按需加載 component: () => import() 報(bào)錯(cuò)的解決
這篇文章主要介紹了vue-router 按需加載 component: () => import() 報(bào)錯(cuò)的解決,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09
Vue中使用localStorage存儲(chǔ)token并設(shè)置時(shí)效
這篇文章主要為大家介紹了Vue中使用localStorage存儲(chǔ)token并設(shè)置時(shí)效,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06
Vue.js中用v-bind綁定class的注意事項(xiàng)
關(guān)于數(shù)據(jù)綁定一個(gè)常見需求就是操作元素的class列表和它的內(nèi)聯(lián)樣式。因?yàn)樗鼈兌际菍傩?,我們可以?v-bind 處理它們,但是使用v-bind綁定class的時(shí)候我們要有一些注意事項(xiàng),下面這篇文章就給大家分享了下要注意的方面,希望能對大家有所幫助,下面來一起看看吧。2016-12-12
vue 項(xiàng)目中實(shí)現(xiàn)按鈕防抖方法
這篇文章主要介紹了vue 項(xiàng)目中實(shí)現(xiàn)按鈕防抖方法,首先需要新建 .js文件存放防抖方法,引入防抖文件,methods中添加方法,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12
vue.js移動(dòng)數(shù)組位置,同時(shí)更新視圖的方法
下面小編就為大家分享一篇vue.js移動(dòng)數(shù)組位置,同時(shí)更新視圖的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03

