<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, ""); },