前端很多框架 不一一举例
此处以Vue进行举例
@Watch('Str' , {immediate:true})
private changeFarmName(newVal:string){
this.Strcount = 0
this.Numcount = 0
this.$nextTick(() =>{
let doms:any = document.getElementById('inputId')
//循环字符串
for(let i = 0; i<newVal.length ; i ++){
if(escape(newVal[i]).indexOf("%u") < 0){
this.Numcount++
}else{
this.Strcount++
}
}
console.log( this.Strcount , this.Numcount)
if((this.Strcount * 4) + (this.Numcount*2 ) > 40){
console.log(doms.rows + 'rows')
doms.rows = 2
}else{
console.log(doms.rows + 'rows')
doms.rows = 1
}
})
}
此处只是提供思路 优化还需自己慢慢优化