可以通过在 el-input 组件中加入 slot 来实现给 suffix-icon 添加点击事件。

例如,在 el-input 中加入以下代码:

<el-input v-model='input' placeholder='请输入内容'>
  <template slot='suffix'>
    <i class='el-icon-search' @click='handleClick'></i>
  </template>
</el-input>

其中,@click 绑定了一个名为 handleClick 的事件处理函数。在 Vue 实例中定义这个函数即可实现点击事件的功能。

new Vue({
  el: '#app',
  data: {
    input: ''
  },
  methods: {
    handleClick() {
      console.log('search clicked')
    }
  }
})

原文地址: https://www.cveoy.top/t/topic/nTkF 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录