浏览代码

封装store

wangwei 4 年之前
父节点
当前提交
5365bfe3e7
共有 4 个文件被更改,包括 6 次插入8 次删除
  1. 3 1
      src/api/require.js
  2. 2 1
      src/api/urls.js
  3. 0 2
      src/components/Login.vue
  4. 1 4
      src/store/modules/app/actions.js

+ 3 - 1
src/api/require.js

@@ -1,8 +1,10 @@
 // 导入封装好的网络请求类工具
 import http from './http';
 import urls from './urls'
+
 // 封装各种接口请求
 export default require = {
-  test: (params) => http.get(urls.test_url, params),
+  test: (params) => http.get(urls.login_url, params),
   login: (params) => http.post(urls.login_url, params),
+  register: (params) => http.post(urls.register_url, params),
 }

+ 2 - 1
src/api/urls.js

@@ -1,4 +1,5 @@
-export default urls = {
+export default {
   login_url: '/login',
+  register_url: '/register',
   test_url: '/test',
 }

+ 0 - 2
src/components/Login.vue

@@ -50,8 +50,6 @@ export default {
       // console.log(`init===`, this.$socket.id);
     },
     login() {
-      console.log(`process`, process.env)
-      console.log(`process`, process.env.API_URL)
       const apiurl = process.env.API_URL
       console.log(`apiurl`, apiurl)
       if (this.$socket.id) {

+ 1 - 4
src/store/modules/app/actions.js

@@ -2,13 +2,10 @@
 import require from '@/api/require'
 import { processReturn } from '@/utils/common';
 import { SET_USER, SET_TOKEN, SET_LOADING } from './mutation-types';
-
 const actions = {
   async register({ commit }, payload) {
     commit(SET_LOADING, true);
-    const res = await axios.post('/auth/register', {
-      ...payload,
-    });
+    const res = await require.register({...payload})
     const data = processReturn(res);
     commit(SET_LOADING, false);
     if (data) {