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