<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 裏面的方法this
trimLR(val) { this[val] = this[val].replace(/\s+/g, ""); },
上面的類型是serchText是直接在data裏面的,若是有其餘嵌套好比
data(){code
return { info:{ tex:"" } }
}事件
上面修改成 @keyup.native="trimLR('info','tex')" 具體方法修改成
trimLR(val,val1) {input
this[val][val1] = this[val][val1].replace(/\s+/g, ""); },