Home  >  Article  >  Web Front-end  >  How to implement fuzzy query in vue input box

How to implement fuzzy query in vue input box

php中世界最好的语言
php中世界最好的语言Original
2018-05-28 12:01:568372browse

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 the

string, 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>
The effect is as follows:

Believe it After reading the case in this article, you have mastered the method. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn