<template>
<div class="hello">
<el-form :model="ruleForm" :rules="ruleValidate">
<el-form-item prop="number">
<el-input labe="输入数字" v-model="ruleForm.number" placeholder="请输入数字" ></el-input>
</el-form-item>
</el-form>
<h1>{{ msg }}</h1>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
data () {
let checkPrice = (rule,value,callback)=>{
if(value){
// let rgx = /^\d+(\.\d{1,2})?$/;
let rgx = /^[1-9]{1}\d{0,16}(\.\d{1,2})?$|^0(\.\d{1,2})?$/;
if(value.match(rgx)==null){
return callback(new Error('请检查输入格式,不能为空,且最多2位小数'))
}else{
callback();
}
}
};
return {
msg: 'Welcome to Your Vue.js App',
ruleForm:{
number:''
},
ruleValidate:{
number:[
{ required: true, message: '请输入数字', trigger: 'change' },
{ validator:checkPrice,trigger:'change'}
]
}
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
font-weight: normal;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
网友评论