Vue+Vant implements the top search bar

Vue+Vant implements the top search bar

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

Search bar component source code (SearchBar.vue)

<template>
  <section class="city-search">
    <van-icon class="search-icon" name="search" />
    <input placeholder="Enter the search keyword here" v-model="KeyWord">
    <van-icon class="clear-icon" name="clear" v-show="KeyWord" @click="clearSearchInput" />
  </section>
</template>
 
<script>
export default {
   data() {
        return {
            KeyWord: '',
        }
    },
    methods: {
        clearSearchInput() {
            this.KeyWord = '';
        }
    }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
    .city-search {
        background-color: #F7F8FA;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        height: 2.3rem;
        width: 94vw;
        margin: 2vw 4vw;
        border-radius: 8px;
    }
    .search-icon {
      margin-left: 5px;
    }
    input {
      margin: 0 1.5vw;
      background-color: #F7F8FA;
      border: 0px;
      font-size: 14px;
      flex: 1
    }
    .clear-icon { color: #999;}
  
</style>

Other components rely on reference retrieval components

Home page reference search component:

<template>
  <div>
      <search></search>
        Home</div>
</template>
 
<script>
import Search from '@/components/SearchBar'
export default {
   name: "home",
   components:
      'search': Search,
    },
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
 
</style>

Effect screenshots:

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:
  • Vue elementui implements the example code of the search bar public component encapsulation

<<:  Solution to the problem of MySQL thread in Opening tables

>>:  Detailed explanation of how to install the system on VMware workstation 14 pro (virtual machine)

Recommend

VMware Workstation virtual machine installation operation method

Virtual machines are very convenient testing soft...

W3C Tutorial (7): W3C XSL Activities

A style sheet describes how a document should be ...

Detailed explanation of JavaScript stack and copy

Table of contents 1. Definition of stack 2. JS st...

A super detailed Vue-Router step-by-step tutorial

Table of contents 1. router-view 2. router-link 3...

MySQL 8.0 Window Function Introduction and Summary

Preface Before MySQL 8.0, it was quite painful to...

SQL Aggregation, Grouping, and Sorting

Table of contents 1. Aggregate Query 1. COUNT fun...

Use Vue3+Vant component to implement App search history function (sample code)

I am currently developing a new app project. This...

How to set up cross-domain access in IIS web.config

Requirement: The page needs to display an image, ...

MySql quick insert tens of millions of large data examples

In the field of data analysis, database is our go...

Example of using supervisor to manage nginx+tomcat containers

need: Use docker to start nginx + tomcat dual pro...

mysql delete multi-table connection deletion function

Deleting a single table: DELETE FROM tableName WH...

CSS3 new layout: flex detailed explanation

Flex Basic Concepts Flex layout (flex is the abbr...

Docker View JVM Memory Usage

1. Enter the host machine of the docker container...

js realizes 3D sound effects through audioContext

This article shares the specific code of js to ac...

Several ways to set the expiration time of localStorage

Table of contents Problem Description 1. Basic so...