Browse Source

change axios

lushuncheng 7 years ago
parent
commit
3f70f5e23a
1 changed files with 10 additions and 8 deletions
  1. 10 8
      plugins/nuxtAxios.js

+ 10 - 8
plugins/nuxtAxios.js

@@ -23,17 +23,19 @@ export default function ({ $axios, redirect, req, ...args }) {
         if (config.method === 'post' && !isUpload) {
             // config.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
             const data = config.data;
-            // const cookie = config.headers.cookie || config.headers.common.cookie || '';
-            let formData = '';
-            for(const key in data) {
+            if (typeof data != "string") {
+              // const cookie = config.headers.cookie || config.headers.common.cookie || '';
+              let urlParams = [];
+              for(const key in data) {
                 if(data.hasOwnProperty(key)) {
-                    const element = data[key];
-                    formData += `${key}=${element}&`;
+                  const element = encodeURI(data[key])
+                  urlParams.push(`${key}=${element}`)
                 }
+              }
+              // formData += cookie.split(';').join('&');
+              config.data = urlParams.join('&');
+              // config.data = qs.stringify(config.data);
             }
-            // formData += cookie.split(';').join('&');
-            config.data = formData;
-            // config.data = qs.stringify(config.data);
         }
         console.log('After, making request to ', config.url, config.baseURL)
         return config;