我正在嘗試驗證文本欄位值,以便最多包含 4 個字符,不包括“。” 特點。
<v-text-field
v-model="diagnoseCode"
style="height: 38px"
outlined
dense
maxLength="4">
</v-text-field>
我已經嘗試過了,但這并沒有考慮到“。”的檢查。特點。任何幫助都將不勝感激。
uj5u.com熱心網友回復:
您可以使用方法設定最大長度:
new Vue({
el: '#app',
vuetify: new Vuetify(),
data() {
return {
diagnoseCode: null,
max: null
}
},
methods: {
clear() {
this.max = null
},
check(e) {
str = this.diagnoseCode
if (str.replaceAll('.', '').length > 4 && !this.diagnoseCode.endsWith('.')) {
this.diagnoseCode = this.diagnoseCode.slice(0,-1)
this.max = this.diagnoseCode.length
}
}
},
})
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css" rel="stylesheet">
<div id="app">
<v-app>
<v-main>
<v-container>
<v-text-field v-model="diagnoseCode"
style="height: 38px"
outlined
dense
:maxLength="max"
@keyup="check($event.target.value)"
@keydown="clear">
</v-text-field>
</v-container>
</v-main>
</v-app>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.js"></script>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/417273.html
標籤:
上一篇:href標簽破壞了Vue模板組件
