no message

Former-commit-id: 487ad37396f6f4c6afda02ba5388968fd16c2323
Former-commit-id: 48aeae5cb653e147b29bb61fe7f93e5450f672f4
Former-commit-id: c1dc76f850cd0447620be74f7835bab7e38bf060
This commit is contained in:
李杨
2018-01-22 13:49:11 +08:00
parent 4f92a792f9
commit da0c3647c5
3 changed files with 57 additions and 3 deletions

View File

@@ -1 +1,3 @@
import '@/mock/demo/001'
import '@/mock/login'

36
src/mock/login/index.js Normal file
View File

@@ -0,0 +1,36 @@
import Mock from 'mockjs'
const userDB = [
{
username: 'admin',
password: 'admin'
},
{
username: 'FairyEver',
password: '000000'
},
{
username: 'user1',
password: '111111'
},
{
username: 'user2',
password: '222222'
}
]
Mock.mock('/login', 'post', ({url, type, body}) => {
const bodyObj = JSON.parse(body)
const user = userDB.find(e => e.username === bodyObj.username && e.password === bodyObj.password)
if (user) {
return {
code: 0,
msg: '登陆成功'
}
} else {
return {
code: 500,
msg: '没有找到匹配的用户'
}
}
})

View File

@@ -70,10 +70,26 @@ export default {
submit () {
this.$refs.loginForm.validate((valid) => {
if (valid) {
alert('submit!');
this.$axios({
method: 'post',
url: '/login',
data: {
username: this.formLogin.username,
password: this.formLogin.password
}
})
.then (res => {
if (res.data.code === 0) {
this.$message.success(res.data.msg)
setTimeout(() => {
this.$router.push('index')
}, 300);
} else {
this.$message.error(res.data.msg)
}
})
} else {
console.log('error submit!!');
return false;
return false
}
})
}