This time I will show you how to implement fuzzy query of vue input input box, and what are the precautions to implement fuzzy query of vue input input box. The following is a practical case, let's take a look.
Vue fuzzy query function
Principle: The search() method of native js is used to retrieve the substring specified in thestring, Or retrieve a substring that matches the regular expression. If no matching substring is found, -1 is returned.
Input input box, fuzzy query
<template> <p> <input type="text" placeholder="请输入..." v-model="searchVal"> <ul> <li v-for="(item,index) in NewItems" :key="index" :value="item.value" v-text="item.name"></li> </ul> </p> </template> <script> export default { name: "HelloWorld", data() { return { searchVal: "", items: [ { name: "上海", value: "sh" }, { name: "北京", value: "bj" }, { name: "重庆", value: "cq" }, { name: "嗨嗨嗨", value: "hhh" }, { name: "海上", value: "hs" }, { name: "京都", value: "jd" } ] }; }, methods: {}, computed: { NewItems() { var _this = this; var NewItems = []; this.items.map(function(item) { if (item.name.search(_this.searchVal) != -1) { NewItems.push(item); } }); return NewItems; } } }; </script>
How to build an mpvue applet project
Detailed explanation of the steps for using Jsonp in VUE2.0
The above is the detailed content of How to implement fuzzy query in vue input box. For more information, please follow other related articles on the PHP Chinese website!