这篇文章主要介绍vue如何实现搜索小功能,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
具体内容如下
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <div id="app"> <input type="text" v-model="keyword" placeholder="输入关键字" /> <div class="list"> <div class="item" v-for="item in fFruit" :key="item"> {{item}} </div> </div> </div> </body> <script src="js/vue.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> new Vue({ el:"#app", data(){ return{ keyword:"", fruit:[ "苹果","沙果","海棠","野樱莓","枇杷","欧楂","山楂","香梨", "雪梨 ","温柏","蔷薇果","花楸","杏","樱桃","桃","水蜜桃", "油桃","蟠桃","李子","梅子","西梅","白玉樱桃 ","黑莓", "覆盆子","云莓","罗甘莓","白里叶莓","草莓","菠萝莓","橘子", "砂糖桔","橙子","柠檬","青柠","柚子","金桔","葡萄柚","香橼", "佛手","指橙","黄皮果","哈密瓜","香瓜","白兰瓜","刺角瓜" ] } }, computed:{ "fFruit"(){ // 如果关键字为空,返回所有的水果 if(this.keyword==""){ return this.fruit; }else{ // 当Frui里面某一项文字包含keyword文字那么就把当前数据保留 // filter过滤 返回为真保留,为false就过滤掉 return this.fruit.filter(item=>{ return item.includes(this.keyword) }) } } } }) </script> </html>
结果:
以上是“vue如何实现搜索小功能”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。