1、filters用处:对数据进行过滤操作
2、用法示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<title>filters过滤器 </title>
</head>
<body>
<div id="app">
<div>
{{info.name}}
{{info.money | fil1 | fil2}}
</div>
</div>
<script>
var vm = new Vue({
el:"#app",
data(){
return {
info:{
name : "张三",
money:100
}
}
},
filters:{
fil1(val){
return val*2
},
fil2(val){
return val+"元"
}
},
});
</script>
</body>
</html>
3、注意和es6的filter方法进行区分
- filter 方法,筛选出数组中符合条件的所有元素,然后创建一个新的数组
var list = [1,2,3,4];
var newList = list.filter(ele => ele > 2);
console.log(list,newList)