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

Use a few interview questions to look at the JavaScript execution mechanism

Table of contents Previous words Synchronous and ...

React Native startup process detailed analysis

Introduction: This article takes the sample proje...

How to clear floating example code in css

Overview The framework diagram of this article is...

Solution to the error reported by Mysql systemctl start mysqld

Error message: Job for mysqld.service failed beca...

Debian virtual machine created by VirtualBox shares files with Windows host

the term: 1. VM: Virtual Machine step: 1. Downloa...

Summary of experience in using div box model

Calculation of the box model <br />Margin + ...

Diagram of the process of implementing direction proxy through nginx

This article mainly introduces the process of imp...

Three common style selectors in html css

1: Tag selector The tag selector is used for all ...

Implementation of form submission in html

Form submission code 1. Source code analysis <...

Detailed explanation of storage engine in MySQL

MySQL storage engine overview What is a storage e...

In-depth analysis of the role of HTML <!--...--> comment tags

When we check the source code of many websites, w...

How to open MySQL binlog log

binlog is a binary log file, which records all my...

vue-electron problem solution when using serialport

The error is as follows: Uncaught TypeError: Cann...

How to use Docker Compose to implement nginx load balancing

Implement Nginx load balancing based on Docker ne...