From f0ffd89af29ec107f2f8f7a540f44db693578f51 Mon Sep 17 00:00:00 2001 From: "jqtmviyu@gmail.com" Date: Fri, 15 Jan 2021 11:18:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E7=99=BB=E5=BD=95=E9=A1=B5=E7=9A=84?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E7=A7=BB=E5=8A=A8=E5=88=B0=20vuex=20?= =?UTF-8?q?=E9=87=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/user.js | 9 +++++++++ src/views/login/index.vue | 7 +------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 8e6fd1f..18c608b 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -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 { diff --git a/src/views/login/index.vue b/src/views/login/index.vue index d6f829a..3cb94be 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -57,8 +57,6 @@