(1).只能输入数字
<template>
<view>
<input type="text" placeholder="请输入款号" placeholder-style='color:#808080' v-model="cargoNo" @input='inputClick'>
</view>
</template>
<script>
export default {
data() {
return {
cargoNo: ''
}
},
methods: {
inputClick(e) {
const o = e.detail.value
const inputRule = /[^\d]/g
this.$nextTick(() => {
this.cargoNo = o.replace(inputRule, '');
if (this.cargoNo == '') {
return
} else {
//执行对应代码
}
})
},
}
}
</script>
(2).输入值的大小范围
<template>
<view>
<input
v-model="valueScore"
placeholder-style="color:#999999"
placeholder="请输入得分"
type="number"
@blur="handleInput()"
/>
</view>
</template>
<script>
export default {
data() {
return {
valueScore: "",
score: 4,
};
},
methods: {
handleInput() {
if (Number(this.valueScore) > this.score) {
this.valueScore = this.score;
} else if (Number(this.valueScore) < 0) {
this.valueScore = 0;
}
},
},
};
</script>
@input 中如果要进行传参 写法(@input="方法名字($event,参数)")
@input="getQty($event,index)"
使用时
getQty(event, index) {
}
split分割符号
单个符号分割 split(",") //逗号分隔
多个符号分割 split(/,| |,/) //逗号(中英文),空格