Browse Source

跨域处理

baid222u 4 years ago
parent
commit
46223bb02b
4 changed files with 23 additions and 6 deletions
  1. 9 0
      components/areaSelect.vue
  2. 10 3
      nuxt.config.js
  3. 0 1
      pages/index.vue
  4. 4 2
      plugins/axios.js

+ 9 - 0
components/areaSelect.vue

@@ -71,6 +71,15 @@ export default {
       this.current2 = [].concat(this.current2)
     },
     coolse:function(){
+      var g=""
+      for(var i=0;i<this.current2.length;i++){
+        if(this.current2[i]=='active'){
+          if(i>10){
+            
+          }
+        }
+      }
+      console.log(this.current2)
        this.$emit('province','4545454456456');
     }
   }

+ 10 - 3
nuxt.config.js

@@ -39,6 +39,7 @@ export default {
   modules: [
     // Doc: https://axios.nuxtjs.org/usage
     '@nuxtjs/axios',
+    '@nuxtjs/proxy',
     // Doc: https://bootstrap-vue.js.org/docs/
     'bootstrap-vue/nuxt',
     '@nuxtjs/pwa',
@@ -49,11 +50,17 @@ export default {
   axios: {
     // See https://github.com/nuxt-community/axios-module#options
   },
-  proxy: {
-
+  proxy: [
 
+    [
+      '/api', 
+      { 
+        target: 'https://gcb.china0001.com.cn/pubdata', // api主机
+        pathRewrite: { '^/api' : '/' }
+      }
+  ]
 
-  },
+],
   /*
    ** Build configuration
    */

+ 0 - 1
pages/index.vue

@@ -168,7 +168,6 @@ export default {
       } else {
         this.b = false
       }
-
       console.log(this.b)
       this.close()
     }

+ 4 - 2
plugins/axios.js

@@ -1,8 +1,10 @@
 export default function (app) {
-  let axios = app.$axios; 
+  let axios = app.$axios;
+  let options = {} 
  // 基本配置
   axios.defaults.timeout = 10000
-  axios.defaults.baseURL = 'https://gcb.china0001.com.cn/pubdata'
+  axios.defaults.baseURL = `http://${process.env.HOST || 'localhost'}:${process.env.PORT || 3000}/api`
+  //axios.defaults.baseURL = 'https://gcb.china0001.com.cn/pubdata'
   axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
   axios.interceptors.request.use(function (config) {
     console.log('请求之前做什么')