This commit is contained in:
xing 2020-06-16 15:20:27 +08:00
parent 4a323995f9
commit 40ded001f8
4 changed files with 31 additions and 7 deletions

15
src/components/Home.vue Normal file
View File

@ -0,0 +1,15 @@
<template>
<div>
home组件
</div>
</template>
<script>
export default {
name: 'Home'
}
</script>
<style scoped>
</style>

View File

@ -26,8 +26,8 @@ export default {
data () { data () {
return { return {
loginForm: { loginForm: {
username: '', username: 'admin',
password: '' password: '123456'
}, },
loginFormRules: { loginFormRules: {
username: [ username: [
@ -49,8 +49,11 @@ export default {
} }
const { data: res } = await this.$http.post('login', this.loginForm) const { data: res } = await this.$http.post('login', this.loginForm)
if (res.meta.status !== 200) { if (res.meta.status !== 200) {
return console.log('login fail') return this.$message.error('登录失败')
} }
sessionStorage.setItem('token', res.data.token)
this.$message.success('登录成功')
await this.$router.push('/home')
}) })
}, },
reset () { reset () {

View File

@ -1,6 +1,8 @@
import Vue from 'vue' import Vue from 'vue'
import VueRouter from 'vue-router' import VueRouter from 'vue-router'
import Login from '../components/Login' import Login from '../components/Login'
import Home from '../components/Home'
Vue.use(VueRouter) Vue.use(VueRouter)
const routes = [ const routes = [
@ -10,6 +12,10 @@ const routes = [
{ {
path: '/login', path: '/login',
component: Login component: Login
},
{
path: '/home',
component: Home
} }
] ]

View File

@ -1,6 +1,6 @@
module.exports={ module.exports = {
devServer:{ devServer: {
port:8887, port: 8887,
open:true, open: true
} }
} }