瀏覽代碼

框架搭建

许成详 6 年之前
父節點
當前提交
393d11ba78
共有 5 個文件被更改,包括 88 次插入5 次删除
  1. 1
    1
      config/index.js
  2. 3
    4
      src/main.js
  3. 37
    0
      src/pages/test/test.vue
  4. 6
    0
      src/router/index.js
  5. 41
    0
      src/util/ajax.js

+ 1
- 1
config/index.js 查看文件

@@ -13,7 +13,7 @@ module.exports = {
13 13
     proxyTable: {},
14 14
 
15 15
     // Various Dev Server settings
16
-    host: 'localhost', // can be overwritten by process.env.HOST
16
+    host: '0.0.0.0', // can be overwritten by process.env.HOST
17 17
     port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
18 18
     autoOpenBrowser: false,
19 19
     errorOverlay: true,

+ 3
- 4
src/main.js 查看文件

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

+ 37
- 0
src/pages/test/test.vue 查看文件

@@ -0,0 +1,37 @@
1
+<style lang="sass" scoped>
2
+
3
+</style>
4
+
5
+<template>
6
+  <div>123</div>
7
+</template>
8
+
9
+<script>
10
+export default {
11
+  data () {
12
+    return {
13
+
14
+    }
15
+  },
16
+  mounted () {
17
+    this.$ajax('', {
18
+      method: this.$api.order.orderPage.method,
19
+      data: {
20
+        orderState: status,
21
+        base_pageSize: this.orderData[this.status].base_pageSize,
22
+        base_currentPage: this.orderData[this.status].base_currentPage
23
+      }
24
+    })
25
+      .then(res => {
26
+
27
+      }).catch(msg => {
28
+        this.$toast({
29
+          message: msg.data.message,
30
+          position: 'center',
31
+          duration: 2000
32
+        })
33
+        return false
34
+      })
35
+  }
36
+}
37
+</script>

+ 6
- 0
src/router/index.js 查看文件

@@ -2,6 +2,7 @@ import Vue from 'vue'
2 2
 import Router from 'vue-router'
3 3
 import login from '@/pages/login/index'
4 4
 import system from '@/pages/system/index'
5
+import test from '@/pages/test/test'
5 6
 
6 7
 Vue.use(Router)
7 8
 
@@ -16,6 +17,11 @@ export default new Router({
16 17
       path: '/system',
17 18
       name: 'system',
18 19
       component: system
20
+    },
21
+    {
22
+      path: '/test',
23
+      name: 'test',
24
+      component: test
19 25
     }
20 26
   ]
21 27
 })

+ 41
- 0
src/util/ajax.js 查看文件

@@ -0,0 +1,41 @@
1
+import axios from 'axios'
2
+import { Message } from 'element-ui'
3
+import qs from 'qs'
4
+
5
+const Axios = axios.create({
6
+  timeout: 60000,
7
+  responseType: 'json',
8
+  withCredentials: true,
9
+  headers: {}
10
+})
11
+
12
+Axios.interceptors.request.use((config) => {
13
+  config.data = qs.stringify(config.data)
14
+  return config
15
+}, (error) => {
16
+  console.log(error)
17
+})
18
+
19
+Axios.interceptors.response.use((res) => {
20
+  if (res.data.code === 1) {
21
+    return res
22
+  } else if (res.data.code === 2) {
23
+    Message({
24
+      message: res.data.message,
25
+      position: 'bottom',
26
+      duration: 2000
27
+    })
28
+    return res.data.code
29
+  } else if (res.data.code === 0) {
30
+    Message({
31
+      message: res.data.message,
32
+      position: 'bottom',
33
+      duration: 2000
34
+    })
35
+    return res.data.code
36
+  }
37
+}, (error) => {
38
+  console.log(error)
39
+})
40
+
41
+export default Axios