vue中limitBy,filterBy,orderBy的用法

1.limitBy的用法

<body>
<div id="box">
<ul>
<li v-for="val in arr | limitBy 2 1"> <!-- 从index=1的位置取两个-->
{{val}}
</li>
</ul>
</div>
<script>

var vm=new Vue({
data:{
arr:[1,2,3,4,5]
},
methods:{

}
}).$mount('#box');

</script>

2  filterBy的用法:筛选中数组中含有a字母的值

<body>
<div id="box">
<input type="text" v-model="a">
<ul>
<li v-for="val in arr | filterBy a">
{{val}}
</li>
</ul>
</div>
<script>

var vm=new Vue({
data:{
arr:['width','height','background','orange'],
a:''
},
methods:{

}
}).$mount('#box');

</script>
</body>

3 orderBy的用法

<body>
<div id="box">
<input type="text" v-model="a">
<ul>
<li v-for="val in arr | orderBy a">
{{val}}
</li>
</ul>
</div>
<script>

var vm=new Vue({
data:{
arr:['width','height','background','orange'],
a:''
},
methods:{

}
}).$mount('#box');

</script>
</body>

原文地址:https://www.cnblogs.com/zhangzhiqin/p/9491614.html