首先我们来看一下效果图:

具体的代码实现:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
  <div id="app">
	  <el-input  class="innerbox" v-model="input22" class="input-with-select" readonly @keyup.native.delete="clearIpt">
	    <el-button slot="append" icon="el-icon-search" ></el-button>
	</el-input>
  </div>
</body>
  <!-- import Vue before Element -->
  <script src="https://unpkg.com/vue/dist/vue.js"></script>
  <!-- import JavaScript -->
  <script src="https://unpkg.com/element-ui/lib/index.js"></script>

  <script>
    new Vue({
      el: '#app',
      data: function() {
        return { 
        	input22: '11' 
        }
      },
      methods:{
      	clearIpt:function(){
      		this.input22 = '';
      
      	}
      }
    })
  </script>
  </html>

 

这里实用的方法是@keyup.native.delete="",用来监听到键盘的删除事件。

Logo

前往低代码交流专区

更多推荐