当前位置:首页 » 《随便一记》 » 正文

Vue3使用element-ui input组件给字体图标绑定点击事件_懮俍的博客

28 人参与  2022年05月31日 08:02  分类 : 《随便一记》  评论

点击全文阅读


Element - The world's most popular Vue UI framework

想要实现的需求是:实现搜索框回车以及点击搜索按钮能够调用后台接口,更新数据

在使用input组件时可以通过 prefix-icon 和 suffix-icon 属性在 input 组件首部和尾部增加显示图标,也可以通过 slot 来放置图标。

想要使字体图标绑定事件需要用slot来放置图标

<div class="demo-input-suffix">
  属性方式:
  <el-input
    placeholder="请选择日期"
    suffix-icon="el-icon-date"
    v-model="input1">
  </el-input>
  <el-input
    placeholder="请输入内容"
    prefix-icon="el-icon-search"
    v-model="input2">
  </el-input>
</div>
<div class="demo-input-suffix">
  slot 方式:
  <el-input
    placeholder="请选择日期"
    v-model="input3">
    <i slot="suffix" class="el-input__icon el-icon-date"></i>
  </el-input>
  <el-input
    placeholder="请输入内容"
    v-model="input4">
    <i slot="prefix" class="el-input__icon el-icon-search"></i>
  </el-input>
</div>

<script>
export default {
  data() {
    return {
      input1: '',
      input2: '',
      input3: '',
      input4: ''
    }
  }
}
</script>

Vue3中这种写法会报错

Swiper.vue中slot属性报错:slot` attributes are deprecated.eslint-plugin-vue

解决思路:solt的新写法

在外层包一层template

<template>
  <div class="search-wrapper">
    <el-input placeholder="请输入你要搜索的内容" v-model="content" size="mini" @change="searchChange">
      <template v-slot:prefix @click="searchChange">
        <i class="el-input__icon el-icon-search"></i>
      </template>
    </el-input>
  </div>
</template>


点击全文阅读


本文链接:http://zhangshiyu.com/post/41054.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新文章

  • 咸鱼翻身从刷开始(柳如烟李诗琪)_咸鱼翻身从刷开始柳如烟李诗琪
  • 影帝求我别离婚,我转身去了对家列表_影帝求我别离婚,我转身去了对家(季淮顾言陆景行)
  • 点天灯后,偷我勋章的男友疯了(沈娇娇陆沉)_点天灯后,偷我勋章的男友疯了
  • 重生后,我让妻子后悔(云璟陆沈清)
  • 为了给我妈鸣冤,我在我爸六十大寿上毒翻全场(苏恒苏洛),为了给我妈鸣冤,我在我爸六十大寿上毒翻全场
  • 完结文老婆把女儿送给师弟练手后,后悔疯了列表_完结文老婆把女儿送给师弟练手后,后悔疯了(沈安姜向玉)
  • 白月光守寡后,夫君要纳她为妾留青赵恒完本_白月光守寡后,夫君要纳她为妾(留青赵恒)
  • 全书浏览妻子叫我转八十万给实习生(顾祁秦冉)_妻子叫我转八十万给实习生(顾祁秦冉)全书结局
  • 全文男友拿我的生活费给我开亲密付(夏染陈政)列表_全文男友拿我的生活费给我开亲密付
  • 大数据助力,我把妈妈告上法庭欣欣妈妈完本_大数据助力,我把妈妈告上法庭(欣欣妈妈)
  • 年薪百万后,我主动要求给穷光蛋生儿子(李明李小花)全书浏览_年薪百万后,我主动要求给穷光蛋生儿子全书浏览
  • 全书浏览年薪百万后,我主动要求给穷光蛋生儿子(李明李小花)_年薪百万后,我主动要求给穷光蛋生儿子(李明李小花)全书结局

    关于我们 | 我要投稿 | 免责申明

    Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1