将登录页的逻辑移动到 vuex 里面
This commit is contained in:
parent
f1e83bcbf0
commit
f0ffd89af2
@ -1,5 +1,9 @@
|
||||
// import { login, logout, getInfo } from '@/api/user'
|
||||
import { getToken, setToken, removeToken } from '@/utils/auth'
|
||||
|
||||
// 导入登录api
|
||||
import { login } from '@/api/user'
|
||||
|
||||
// import { resetRouter } from '@/router'
|
||||
|
||||
// const getDefaultState = () => {
|
||||
@ -120,6 +124,11 @@ const mutations = {
|
||||
}
|
||||
// 执行异步
|
||||
const actions = {
|
||||
async login({ commit }, data) {
|
||||
const res = await login(data)
|
||||
console.log('将登录页的逻辑移动到 vuex 里面')
|
||||
commit('setToken', res.data.data)
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
|
@ -57,8 +57,6 @@
|
||||
|
||||
<script>
|
||||
import { validMobile } from '@/utils/validate'
|
||||
// 导入登录api
|
||||
import { login } from '@/api/user'
|
||||
|
||||
export default {
|
||||
name: 'Login',
|
||||
@ -129,10 +127,7 @@ export default {
|
||||
async handleLogin() {
|
||||
try {
|
||||
await this.$refs.loginForm.validate()
|
||||
const res = await login(this.loginForm)
|
||||
if (!res.data.success) {
|
||||
this.$store.commit('user/setToken', res.data.data)
|
||||
}
|
||||
this.$store.dispatch('user/login', this.loginForm)
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user