yuantianjiao 6 years ago
parent
commit
dfabdc80ab
5 changed files with 30 additions and 19 deletions
  1. 9
    4
      config/index.js
  2. 3
    4
      src/main.js
  3. 6
    11
      src/pages/test/test.vue
  4. 1
    0
      src/util/ajax.js
  5. 11
    0
      src/util/api.js

+ 9
- 4
config/index.js View File

6
 
6
 
7
 module.exports = {
7
 module.exports = {
8
   dev: {
8
   dev: {
9
-
10
     // Paths
9
     // Paths
11
     assetsSubDirectory: 'static',
10
     assetsSubDirectory: 'static',
12
     assetsPublicPath: '/',
11
     assetsPublicPath: '/',
13
-    proxyTable: {},
14
-
12
+    proxyTable: {
13
+      '/api': {
14
+        target: 'https://dp.huiju360.com.cn/hj_operations', // 接口的域名
15
+        changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
16
+        pathRewrite: {
17
+          '^/api': ''
18
+        },
19
+      },
20
+    },
15
     // Various Dev Server settings
21
     // Various Dev Server settings
16
     host: '0.0.0.0', // can be overwritten by process.env.HOST
22
     host: '0.0.0.0', // can be overwritten by process.env.HOST
17
     port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
23
     port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
39
     // set this to false - it *may* help
45
     // set this to false - it *may* help
40
     // https://vue-loader.vuejs.org/en/options.html#cachebusting
46
     // https://vue-loader.vuejs.org/en/options.html#cachebusting
41
     cacheBusting: true,
47
     cacheBusting: true,
42
-
43
     cssSourceMap: true
48
     cssSourceMap: true
44
   },
49
   },
45
 
50
 

+ 3
- 4
src/main.js View File

6
 import 'element-ui/lib/theme-chalk/index.css'
6
 import 'element-ui/lib/theme-chalk/index.css'
7
 import router from './router'
7
 import router from './router'
8
 import Ajax from './util/ajax'
8
 import Ajax from './util/ajax'
9
-
9
+import api from './util/api'
10
 Vue.use(ElementUI)
10
 Vue.use(ElementUI)
11
-
12
 Vue.config.productionTip = false
11
 Vue.config.productionTip = false
13
-const http = new Ajax()
14
-Vue.prototype.$ajax = http
12
+Vue.prototype.$api = api
13
+Vue.prototype.$ajax = Ajax
15
 /* eslint-disable no-new */
14
 /* eslint-disable no-new */
16
 new Vue({
15
 new Vue({
17
   el: '#app',
16
   el: '#app',

+ 6
- 11
src/pages/test/test.vue View File

14
     }
14
     }
15
   },
15
   },
16
   mounted () {
16
   mounted () {
17
-    this.$ajax('', {
18
-      method: this.$api.order.orderPage.method,
17
+    console.log(this)
18
+    this.$ajax(this.$api.test.area.url, {
19
+      method: 'GET',
19
       data: {
20
       data: {
20
-        orderState: status,
21
-        base_pageSize: this.orderData[this.status].base_pageSize,
22
-        base_currentPage: this.orderData[this.status].base_currentPage
21
+        a: 1,
22
+        b: 2
23
       }
23
       }
24
     })
24
     })
25
       .then(res => {
25
       .then(res => {
26
-
26
+        console.log(res)
27
       }).catch(msg => {
27
       }).catch(msg => {
28
-        this.$toast({
29
-          message: msg.data.message,
30
-          position: 'center',
31
-          duration: 2000
32
-        })
33
         return false
28
         return false
34
       })
29
       })
35
   }
30
   }

+ 1
- 0
src/util/ajax.js View File

10
 })
10
 })
11
 
11
 
12
 Axios.interceptors.request.use((config) => {
12
 Axios.interceptors.request.use((config) => {
13
+  console.log(config)
13
   config.data = qs.stringify(config.data)
14
   config.data = qs.stringify(config.data)
14
   return config
15
   return config
15
 }, (error) => {
16
 }, (error) => {

+ 11
- 0
src/util/api.js View File

1
+const baseUrl = process.env.NODE_ENV === 'development' ? '/api' : 'https://dp.huiju360.com.cn/hj_operations'
2
+// const baseUrl = '/check-api'
3
+const $api = {
4
+  test: { // 测试接口
5
+    area: {
6
+      method: 'get',
7
+      url: `${baseUrl}/machine/area`
8
+    }
9
+  }
10
+}
11
+export default $api