import axios from "axios"; import qs from "qs";//用到了qs插件,安装axios的时候qs插件自动安装了 axiosPost(url, data) { axios.create({headers: {'content-type': 'application/x-www-form-urlencoded'}}); data = qs.stringify(data); return axios.post(url, data); } //把这段代码放入一个公共的util.js里,而后导出就能够用了。 //调用方式 util.axiosPost('xxxxx.do',data).then(resp=>{ //返回结果 }); /** * 使用springMVC为后台的,能够用JSONObject来接收。 * 另一种解决方式: * var aaa = '中文'; * axios.get 里面的参数用encodeURI(encodeURI(aaa),而后后台用 * 后台则是 * URLDecoder.decode(this.getParameter(req, "email", ""),"UTF-8");//email * 不过,推荐仍是用post方式,当请求的时候参数多的时候,还有乱码的时候,都是问题。 */