完成登录功能
This commit is contained in:
parent
931158c079
commit
a62ca5b125
|
|
@ -2,7 +2,7 @@ import {createRouter, createWebHashHistory} from "vue-router";
|
|||
import Login from '../view/login/Login.vue'
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
path: '/home',
|
||||
name: "Home",
|
||||
component: () => import ( /* webpackChunkName: "login" */ "../view/home/Home.vue")
|
||||
},
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ const router = useRouter()
|
|||
const service = axios.create({
|
||||
// process.env.NODE_ENV === 'development' 来判断是否开发环境
|
||||
// baseURL: 'https://www.easy-mock.com/mock/592501a391470c0ac1fab128',
|
||||
baseURL: 'http://192.168.75.32:8000',
|
||||
baseURL: 'http://192.168.10.80:8000/api',
|
||||
timeout: 5000
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
<el-input v-model="param.password" placeholder="请输入密码" />
|
||||
</el-form-item>
|
||||
<el-form-item class="loginBtn">
|
||||
<el-button type="primary" style="margin: 10px" >登录</el-button>
|
||||
<el-button type="primary" style="margin: 10px" @click="submitForm(loginRef)" >登录</el-button>
|
||||
<el-button type="info" style="margin: 10px">取消</el-button>
|
||||
</el-form-item>
|
||||
|
||||
|
|
@ -36,7 +36,6 @@ import { ElMessage } from "element-plus";
|
|||
|
||||
export default {
|
||||
name: "Login",
|
||||
|
||||
setup(){
|
||||
const router = useRouter();
|
||||
const param = reactive({
|
||||
|
|
@ -61,12 +60,18 @@ export default {
|
|||
if (!loginRef) return
|
||||
loginRef.validate((valid) => {
|
||||
if (valid) {
|
||||
Login(param).then((rep)=>{
|
||||
console.log(rep)
|
||||
if (rep.code===200){
|
||||
router.push("/")
|
||||
const formData=new FormData()
|
||||
formData.append("username",param.username)
|
||||
formData.append("password",param.password)
|
||||
Login(formData).then((rep)=>{
|
||||
console.log(rep.data)
|
||||
if (rep.data.code===200){
|
||||
localStorage.setItem("username",rep.data.user.username)
|
||||
localStorage.setItem("token",rep.data.access_token)
|
||||
ElMessage.success(rep.data.message);
|
||||
router.push("/home")
|
||||
}else{
|
||||
ElMessage.error(rep.message);
|
||||
ElMessage.error(rep.data.message);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue