我是靠谱客的博主 霸气期待,这篇文章主要介绍Vue filter 过滤器、以及在table中的使用介绍,现在分享给大家,希望可以做个参考。

使用方法:

复制代码
1
2
3
4
5
// 双花括号中 {{ isActive | isActiveFitlter}} // 在v-bind 中 <div v-bind:id=" isActive | isActiveFitlter"></div>

一、组件中定义本地 Filter

复制代码
1
2
3
4
5
filters:{ isActiveFitlter : (value)=>{ return value===1?'激活':'冻结' } }

二、创建Vue实例前定义全局过滤器

复制代码
1
2
3
4
5
6
Vue.filter('isActiveFitlter', (value)=>{ return value === 1?'激活':'冻结' }) new Vue({ // ... })

三、全局 Filter

1、自定义一个js文件,可以放在common文件夹中

复制代码
1
2
3
4
5
//filters.js let isActiveFitlter = value => { return value===1?'激活':'冻结' } export { isActiveFitlter }

2、main.js 引入 filters.js

复制代码
1
2
3
4
import * as filters from './assets/common/filters' Object.keys(filters).forEach(key => { Vue.filter(key, filters[key]) })

3、组件中使用

<span> {{ isActive | isActiveFitlter }} </span>

注意:

在table中使用需要借助 插槽

复制代码
1
2
3
4
5
<el-table-column prop="isActive" label="状态"> <template slot-scope="scope"> {{scope.row.isActive | isActiveFitlter}} </template> </el-table-column>

补充知识:vue 过滤数组数据,用于控制 el-table 某一行是否显示

场景:第一次查出来的数据用list接收。然后我第二次要用到list里面的数据,但是我想过滤掉选中的某一条用户的信息,这个时候就使用 filter 函数对list 进行 过滤。很简单,做个笔记。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
<el-dialog title="克隆规则" :visible.sync="cloneDialogVisible" width="600px"> <el-table v-loading="listLoading" :data="list2" //绑定的是list2 element-loading-text="Loading" empty-text="没有数据了哦" border fit stripe :row-key="getRowKey" @selection-change="handleSelectionChange" >
复制代码
1
2
3
4
5
6
7
8
9
10
11
//过滤数据代码 showCloneRuleslView(user_id) { this.SourceUserId = parseInt(user_id) //filter过滤函数使用 this.list2 = this.list.filter((data) => { //过滤掉SourceUserId这条数据 return data.user_id !== this.SourceUserId }) this.cloneDialogVisible = true console.log(this.SourceUserId) },

以上这篇Vue filter 过滤器、以及在table中的使用介绍就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持靠谱客。

最后

以上就是霸气期待最近收集整理的关于Vue filter 过滤器、以及在table中的使用介绍的全部内容,更多相关Vue内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(231)

评论列表共有 0 条评论

立即
投稿
返回
顶部