Vue 自定义搜索输入框SearchInput

效果如下:

组件代码

<template>
    <div class="search-input flex flex-space-between flex-center-cz">
        <input type="text" v-model="value" :ref="inpuName" :placeholder="placeholder" @keyup.enter="searchClick"/>
        <img class="pointer" src="@/assets/images/find-blue.png" @click="searchClick">
    </div>
</template>

<script>
    export default {
        name:'SearchInput',
        props:{
            placeholder:{},
            name:{},
            focus:{}
        },
        created(){
            this.inpuName = this.name
        },
        mounted() {
            if (this.focus == 'focus') {
                this.$nextTick(() => {
                    this.$refs[this.inpuName].focus();
                })
            }

        },
        data() {
            return {
                value:''
            }
        },
        methods:{
            searchClick() {
                this.$emit("search", this.value);
            },

        }
    }
</script>

<style scoped>

  .search-input {
    box-sizing: border-box;
    border-radius: 5px;
    padding-left: 8px;
    padding-right: 8px;
    height: 28px;
    background: rgba(255,255,255,0.2);
    box-shadow: 0px 4px 9px 0px rgba(0,81,139,0.16);
    border-radius: 12px;
  }
  .search-input input {
    border: 0;
    width: 100%;
    background: transparent;
  }
  .search-input img {
    width: 12px;
    height: 12px;
  }

</style>

调用代码

 <SearchInput  :placeholder="'请输入文档名或内容查询'" style="width: 300px;" @search="search"></SearchInput>



相关推荐

  1. vue3-定义指令来实现input输入限制

    2023-12-18 18:44:02       5 阅读
  2. Flutter定义TextInputFormatter实现金额输入

    2023-12-18 18:44:02       36 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-18 18:44:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-18 18:44:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-18 18:44:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-18 18:44:02       18 阅读

热门阅读

  1. node之mysql篇经典八小时

    2023-12-18 18:44:02       43 阅读
  2. low private exponent attack

    2023-12-18 18:44:02       45 阅读
  3. 什么是NPM,NPM使用方法

    2023-12-18 18:44:02       37 阅读