Vue implements small search function

Vue implements small search function

This article example shares the specific code of Vue to implement the search function for your reference. The specific content is as follows

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title></title>
 </head>
 <body>
  <div id="app">
   <input type="text" v-model="keyword" placeholder="Enter keyword" />
   <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:
      "Apple", "Sand apple", "Begonia", "Aronia", "Loquat", "Hawthorn", "Hawthorn", "Pear",
      "Snow pear", "Quincea", "Rose hip", "Rannon", "Apricot", "Cherry", "Peach", "Peach",
      "Nectarine", "Peach", "Plum", "Plum", "Prune", "White Jade Cherry", "Blackberry",
      "Raspberry", "Cloudberry", "Loganberry", "Brunette", "Strawberry", "Pineappleberry", "Orange",
      "Sugar orange", "orange", "lemon", "lime", "pomelo", "kumquat", "grapefruit", "citron",
      "Buddha's hand", "Finger orange", "Yellow fruit", "Cantaloupe", "Cantaloupe", "Honey melon", "Prickly horn melon"
     ]
    }
   },
   computed:{
    "fFruit"(){
     // If the keyword is empty, return all fruits if(this.keyword==""){
     return this.fruit;
    }else{
     // When a certain item in Frui contains keyword text, keep the current data // filter returns true to keep, false to filter out return this.fruit.filter(item=>{
      return item.includes(this.keyword)
     })
    }
    }
    
   }
  })
 </script>
</html>

result:

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Implementing a simple search box based on Vue.js
  • How to use vue + element to implement table paging and front-end search
  • Vue.js implements table functions of multi-condition filtering, searching, sorting and paging
  • Vue implements search function
  • Vue Element grouping + multi-selection + searchable Select selector implementation example
  • Vue el-autocomplete remote search drop-down box and implement automatic filling function (recommended)
  • Vue component practice searchable drop-down box function
  • Implementing a custom component for searchable drop-down box based on Vue
  • Vuejs uses filterBy and orderBy to implement search filtering and descending sorting of data
  • Detailed explanation of the use of Vue2.0 multi-condition search component

<<:  Search engine free collection of website entrances

>>:  A brief discussion on the underlying principle of mysql join

Recommend

Who is a User Experience Designer?

Scary, isn't it! Translation in the picture: ...

Detailed explanation of Bind mounts for Docker data storage

Before reading this article, I hope you have a pr...

Solution for Baidu site search not supporting https (tested)

Recently, https has been enabled on the mobile ph...

Example usage of Linux compression file command zip

The ".zip" format is used to compress f...

Detailed explanation of the pitfalls of MySQL 8.0

I updated MySQL 8.0 today. The first problem: Nav...

MySQL 4 methods to import data

1. Import mysql command The mysql command import ...

Implementing Binary Search Tree in JavaScript

The search binary tree implementation in JavaScri...

js to achieve the complete steps of Chinese to Pinyin conversion

I used js to create a package for converting Chin...

Summary of common sql statements in Mysql

1. mysql export file: SELECT `pe2e_user_to_compan...

Steps to create a Vite project

Table of contents Preface What does yarn create d...

JS Decorator Pattern and TypeScript Decorators

Table of contents Introduction to the Decorator P...

Use CSS to set the width of INPUT in TD

Recently, when I was using C# to make a Web progra...

How to use history redirection in React Router

In react-router, the jump in the component can be...