Vue实现自带的过滤器实例(2)

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Vue自带的过滤器</title> <meta content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <script src="https://www.jb51.net/js/vue.js" type="text/javascript" charset="utf-8"></script> </head> <body> <div> <button @click="disappear | debounce 10000">点击我,我将10秒后消失</button> </div> <script type="text/javascript"> var myVue = new Vue({ el: ".test", methods: { disappear: function () { document.getElementById("btn").style.display= "none"; } } }) </script> </body> </html>

八 Vue自带的过滤器:limitBy

(1)限制:需在v-for(即数组)里面使用

(2)两个参数:

第一个参数:{Number} 取得数量

第二个参数:{Number} 偏移量

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Vue自带的过滤器</title> <meta content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <script src="https://www.jb51.net/js/vue.js" type="text/javascript" charset="utf-8"></script> </head> <body> <div> <ul v-for="item in lili | limitBy 10"> <!--输出1 2 3 4 5 6 7 8 9 10--> <li>{{item}}</li> </ul> <ul v-for="item in lili | limitBy 10 3"> <!--输出 4 5 6 7 8 9 10 11 12 13--> <li>{{item}}</li> </ul> </div> <script type="text/javascript"> var myVue = new Vue({ el: ".test", data: { lili: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] } }) </script> </body> </html>

 九 Vue自带的过滤器:filterBy

(1)限制:需在v-for(即数组)里面使用

(2)三个参数:

第一个参数: {String | Function} 需要搜索的字符串

第二个参数: in (可选,指定搜寻位置)

第三个参数: {String} (可选,数组格式)

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Vue自带的过滤器</title> <meta content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <script src="https://www.jb51.net/js/vue.js" type="text/javascript" charset="utf-8"></script> </head> <body> <div> <ul v-for="item in lili | filterBy 'o' "> <!--输出oi oa lo ouo oala--> <li>{{item}}</li> </ul> <ul v-for="item in man | filterBy 'l' in 'name' "> <!--输出lily lucy--> <li>{{item.name}}</li> </ul> <ul v-for="item in man | filterBy 'l' in 'name' 'dada' "> <!--输出lily+undefined lucy+undefined undefined+lsh--> <li>{{item.name+"+"+item.dada}}</li> </ul> </div> <script type="text/javascript"> var myVue = new Vue({ el: ".test", data: { lili: ["oi", "oa", "ll", "lo" ,"ouo" ,"kk" ,"oala"], man: [ //此处注意man是数组,不是对象 {name: "lily"}, {name: "lucy"}, {name: "oo"}, {dada: "lsh"}, {dada: "ofg"} ] } }) </script> </body> </html>

十 Vue自带的过滤器:orderBy

(1)限制:需在v-for(即数组)里面使用

(2)三个参数:

第一个参数: {String | Array<String> | Function} 需要搜索的字符串

第二个参数: {String} 可选参数 order 决定结果升序(order >= 0)或降序(order < 0),默认是升序

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Vue自带的过滤器</title> <meta content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <script src="https://www.jb51.net/js/vue.js" type="text/javascript" charset="utf-8"></script> </head> <body> <div> <!--遍历数组--> <ul v-for="item in lili | orderBy 'o' 1"> <!--输出kk ll oi--> <li>{{item}}</li> </ul> <ul v-for="item in lili | orderBy 'o' -1"> <!--输出oi ll kk--> <li>{{item}}</li> </ul> <!--遍历含对象的数组--> <ul v-for="item in man | orderBy 'name' 1"> <!--输出Bruce Chuck Jackie--> <li>{{item.name}}</li> </ul> <ul v-for="item in man | orderBy 'name' -1"> <!--输出Jackie Chuck Bruce--> <li>{{item.name}}</li> </ul> <!--使用函数排序--> <ul v-for="item in man | orderBy ageByTen"> <!--输出Bruce Chuck Jackie--> <li>{{item.name}}</li> </ul> </div> <script type="text/javascript"> var myVue = new Vue({ el: ".test", data: { lili: ["oi", "kk", "ll"], man: [ //此处注意man是数组,不是对象 { name: 'Jackie', age: 62 }, { name: 'Chuck', age: 76 }, { name: 'Bruce', age: 61 } ] }, methods: { ageByTen: function () { return 1; } } }) </script> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwwffs.html