element-input-去掉中间空格

3次阅读

共计 516 个字符,预计需要花费 2 分钟才能阅读完成。

<template> 
  <div class="each">
    <div class="serch">
      <el-input
        placeholder="搜索入公司名称"
        prefix-icon="el-icon-search"
        @keyup.native="trimLR('serchText')"
        v-model.trim="serchText"
        clearable
        @input="serch"
      ></el-input>
    </div>
<template>

去掉收尾空格不说了就是使用的 v -model.trim
去掉中间空格 采用的是 @keyup.native 监听原生事件
methods 里面的方法

 trimLR(val) {this[val] = this[val].replace(/\s+/g, "");
    },

上面的类型是 serchText 是直接在 data 里面的,如果有其他嵌套比如
data(){

return {
    info:{tex:""}
}

}

上面修改为 @keyup.native=”trimLR(‘info’,’tex’)” 具体方法修改为
trimLR(val,val1) {

  this[val][val1] = this[val][val1].replace(/\s+/g, "");
},

正文完
 0