Browse Source

首页热门任务加载

sunjh 6 years ago
parent
commit
968c0028c3
6 changed files with 47 additions and 24 deletions
  1. 1 1
      config/index.js
  2. 2 1
      package.json
  3. 14 0
      src/api/api.js
  4. 0 0
      src/api/index.js
  5. 18 0
      src/components/Home.vue
  6. 12 22
      src/http.js

+ 1 - 1
config/index.js

@@ -56,7 +56,7 @@ module.exports = {
      * Source Maps
      */
 
-    productionSourceMap: true,
+    productionSourceMap: false,
     // https://webpack.js.org/configuration/devtool/#production
     devtool: '#source-map',
 

+ 2 - 1
package.json

@@ -14,7 +14,8 @@
     "element-ui": "^2.8.2",
     "font-awesome": "^4.7.0",
     "vue": "^2.5.2",
-    "vue-router": "^3.0.1"
+    "vue-router": "^3.0.1",
+    "axios": "latest"
   },
   "devDependencies": {
     "autoprefixer": "^7.1.2",

+ 14 - 0
src/api/api.js

@@ -0,0 +1,14 @@
+export default {
+  API: {
+    TEST_API: '/api/crowd/test/'
+  },
+  PROJECT: {
+
+  },
+  TASK: {
+    GET_HOT_TASK_LIST: ''
+  },
+  USER: {
+
+  }
+}

+ 0 - 0
src/api/index.js


+ 18 - 0
src/components/Home.vue

@@ -47,6 +47,8 @@
 import TaskCard from "@/components/commons/TaskCard";
 import InstitutionRank from "@/components/InstitutionRank";
 import PersonRank from "@/components/PersonRank";
+import Http from '@/http.js';
+import Apis from '@/api/api.js';
 export default {
   name: "Home",
   components: { TaskCard, InstitutionRank, PersonRank },
@@ -93,6 +95,22 @@ export default {
     };
   },
   methods:{
+    //加载数据
+    loadData:function() {
+      console.log('loadData')
+      this.taskList = this.getHotTaskList()
+    },
+    //获取热门任务列表
+    getHotTaskList:function() {
+      console.log('getHotTaskList')
+      Http.get(Apis.TASK.GET_HOT_TASK_LIST).then((res) =>{
+        return res.data;
+      })
+    }
+  },
+  created:function () {
+    console.log("加载中")
+    this.loadData()
   }
 };
 </script>

+ 12 - 22
src/http.js

@@ -34,7 +34,7 @@ function handleResults (response) {
 }
 
 function handleUrl (url) {
-  url = BASE_URL + url
+  url = 'http://crowd.mooctest.net' + url
   return url
 }
 
@@ -82,27 +82,16 @@ export default {
    * @param response 请求成功时的回调函数
    * @param exception 异常的回调函数
    */
-  get (url, response, exception) {
-    axios({
-      method: 'get',
-      url: handleUrl(url),
-      timeout: TIME_OUT_MS,
-      headers: {
-        'Content-Type': 'application/json; charset=UTF-8'
-      }
-    }).then(
-      (result) => {
-        response(handleResults(result))
-      }
-    ).catch(
-      (error) => {
-        if (exception) {
-          exception(error)
-        } else {
-          console.log(error)
-        }
-      }
-    )
+  get (url, data) {
+    return new Promise((resolve, reject) => {
+      axios.get(handleUrl(url), {
+        params: data
+      }).then((res) => {
+        resolve(res)
+      }).catch((error) => {
+        reject(error)
+      })
+    })
   },
   /*
    * 导入文件
@@ -197,3 +186,4 @@ export default {
     )
   }
 }
+