驗證輸入字符串必須爲數字html
html:git
<FormItem label="兌換積分:" prop="exchangeIntegral"> <Input v-model="formSpecAdd.exchangeIntegral" placeholder="請輸入兌換積分" style="width: 250px"></Input> </FormItem> <FormItem label="庫存數量:" prop="stockNum"> <Input v-model="formSpecAdd.stockNum" placeholder="請輸入庫存數量" style="width: 250px"></Input> </FormItem> <FormItem label="商品價值:" prop="productMoney"> <Input v-model="formSpecAdd.productMoney" placeholder="請輸入商品價值" style="width: 250px"></Input> </FormItem>
js:github
exchangeIntegral: [ {required: true, message: '請輸入兌換積分', trigger: 'blur'}, {type: 'string', pattern: /^\d+$/, message: '請輸入數字', trigger: 'blur'} ], stockNum: [ {required: true, message: '請輸入庫存數量', trigger: 'blur'}, {type: 'string', pattern: /^\d+$/, message: '請輸入數字', trigger: 'blur'} ], productMoney: [ {required: true, message: '請輸入商品價值', trigger: 'blur'}, {type: 'string', pattern: /^\d+$/, message: '請輸入數字', trigger: 'blur'} ],
或者: 直接將輸入框定義爲 number類型iview
<FormItem label="兌換積分:" prop="exchangeIntegral"> <Input v-model="formSpecAdd.exchangeIntegral" number placeholder="請輸入兌換積分" style="width: 250px"></Input> </FormItem>
js:驗證async
exchangeIntegral: [ {required: true, type: 'number', message: '請輸入兌換積分', trigger: 'blur'}, {type: 'number', message: '請輸入數字', trigger: 'blur'} ],
請參考:ui
http://www.javashuo.com/article/p-srbmfpgf-be.htmlspa