wukunlin 5 years ago
parent
commit
c01f741fca

+ 1 - 0
app/package.json

@@ -8,6 +8,7 @@
     "lint": "vue-cli-service lint"
   },
   "dependencies": {
+    "axios": "^0.18.0",
     "core-js": "^2.6.5",
     "element-ui": "^2.8.0",
     "vue": "^2.6.10",

+ 34 - 0
app/src/api/createHttp.js

@@ -0,0 +1,34 @@
+import axios from 'axios'
+import Qs from 'qs'
+
+
+
+export default function createHttp (host) {
+  let ax = axios.create({
+    baseURL: host,
+    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
+    transformRequest: [function (data) {
+      data = Qs.stringify(data)
+      return data
+    }],
+    transformResponse: [],
+    withCredentials: true
+  })
+
+
+  // 拦截器处理错误
+  ax.interceptors.response.use(
+    async response => {
+        if( response.data.rs) {
+            return Promise.resolve(response)
+        } else {
+            return Promise.reject(response)
+        }
+    },
+    error => {
+      return Promise.reject(error)
+    }
+  )
+
+  return ax
+}

+ 11 - 0
app/src/api/http.js

@@ -0,0 +1,11 @@
+import createHttp from './createHttp'
+let host = ''
+if (/^dev./.test(window.location.host)) {
+  host = '//pagegame-api.webdev2.duowan.com'
+} else if (/^new./.test(window.location.host)) {
+  host = '//pagegame-api.webdev2.duowan.com'
+} else {
+  host = '//pagegame-api.webdev2.duowan.com'
+}
+
+export default createHttp(host)

+ 5 - 0
app/src/api/index.js

@@ -0,0 +1,5 @@
+import index from './modules/index'
+
+export default {
+    index
+}

+ 7 - 0
app/src/api/modules/index.js

@@ -0,0 +1,7 @@
+import ax from '../http'
+
+export default {
+    getTypes () {
+        return ax.get('game/types')
+    }
+}

+ 4 - 1
app/src/components/index/banner/index.vue

@@ -14,10 +14,13 @@
 <script>
 import Vue from 'vue';
 import {Carousel, CarouselItem} from 'element-ui'
+import API from '@/api/'
 Vue.use(Carousel)
 Vue.use(CarouselItem)
 export default {
-    
+    mounted () {
+        API.index.getTypes()
+    }
 }
 </script>
 <style lang="scss">