我使用vue.js,并具有以下逻辑输入:onkeypress="return (event.charCode == 8 || event.charCode == 0 || event.charCode == 13) ? null : event.charCode >= 48 && event.charCode <= 57"
它只允许输入从0
到9
的数字。
在我的data()
头中,我有limitMin: 20
,并希望将其包括在输入验证中。因此,如果是limitMin: 20
,那么我只能输入20以上的数字。
<input
type="number"
:min="this.limitMin"
onkeypress="return (event.charCode == 8 || event.charCode == 0 || event.charCode == 13) ? null : event.charCode >= 48 && event.charCode <= 57">
答案 0 :(得分:1)
您可以这样做。
new Vue({
el: "#app",
data: {
inputValue: 1,
limitMin: 20
},
methods: {
validate: function() {
if (this.inputValue >= this.limitMin) {
this.inputValue = this.limitMin;
}
}
}
});
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
<div id="app">
<input
type="number"
v-model="inputValue"
@input="validate">
</div>