import axios from 'axios' /** * 对象的深度拷贝方法 * @params {obj} 对象值 * return obj * */ export function clone(obj) { // Handle the 3 simple types, and null or undefined or function if (null == obj || "object" != typeof obj) return obj; // Handle Date if (obj instanceof Date) { var copy = new Date(); copy.setTime(obj.getTime()); return copy; } // Handle Array or Object if (obj instanceof Array | obj instanceof Object) { var copy = (obj instanceof Array) ? [] : {}; for (var attr in obj) { if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]); } return copy; } } export function Vuehttp(json = {}, url) { let params = new FormData() if ('object' != typeof json) { throw new Error("json is not a obj"); } for (let i of Object.keys(json)) { if (json[i] instanceof Array) { params.append(i, json[i][0]) } else if (typeof json[i] === 'object') { params.append('params', JSON.stringify(json[i])) } else { params.append(i, json[i]) } } let config = { headers: {'Content-Type': 'multipart/form-data'} } // console.log(params) return axios.post(url, params, config) }