Created
February 28, 2018 04:05
-
-
Save yarving/358e34040efa98b3e74a2dc811e903c7 to your computer and use it in GitHub Desktop.
This is a demo for vue validater. Data won't save unless pass date validate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="login"> | |
<div class="login-wrap"> | |
<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="0px" class="demo-ruleForm"> | |
<el-form-item prop="username"> | |
<el-input v-model="ruleForm.username" placeholder="username"></el-input> | |
</el-form-item> | |
<el-form-item prop="password"> | |
<el-input type="password" placeholder="password" v-model="ruleForm.password" @keyup.enter.native="submitForm('ruleForm')"></el-input> | |
</el-form-item> | |
<div class="login-btn"> | |
<el-button type="primary" @click="submitForm('ruleForm')">登录</el-button> | |
</div> | |
<p style="font-size:12px;line-height:30px;color:#999;">Tips : 用户名和密码随便填。</p> | |
</el-form> | |
</div> | |
</div> | |
<script> | |
export default { | |
data() { | |
return { | |
ruleForm: { | |
username: '', | |
password: '' | |
}, | |
rules: { | |
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }], | |
password: [{ required: true, message: '请输入密码', trigger: 'blur' }] | |
} | |
} | |
}, | |
methods: { | |
submitForm(formName) { | |
const self = this | |
self.$refs[formName].validate(valid => { | |
if (valid) { | |
localStorage.setItem('username', self.ruleForm.username) | |
self.$router.push('/home') | |
} else { | |
console.log('error submit!!') | |
return false | |
} | |
}) | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment