WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2020-12-24 5510f41e111068a91bbba1ade732c920bb67f248
转换数组、对象参数请求数据格式
1 files modified
15 ■■■■■ changed files
bases/Fetcher.js 15 ●●●●● patch | view | raw | blame | history
bases/Fetcher.js
@@ -4,6 +4,7 @@
 */
import Taro from '@tarojs/taro';
import Qs from 'qs';
import {Tools} from '@components/common/Tools';
export class Fetcher {
@@ -80,6 +81,12 @@
     * @return {Promise<any>}
     */
    get(url, data, remap = [], options = null) {
        const params = Qs.stringify(data);
        if (url.indexOf('?') >= 0) {
            url += '&' + params;
        } else {
            url += '?' + params;
        }
        return this.query('get', url, null, remap, options);
    }
@@ -92,7 +99,13 @@
     * @return {Promise<any>}
     */
    post(url, data, remap = [], options = null) {
        return this.query('post', url, data, remap, options);
        const params = Qs.stringify(data);
        const data2 = {};
        params.split('&').forEach(param => {
            const item = param.split('=');
            data2[decodeURIComponent(item[0])] = decodeURIComponent(item[1]);
        });
        return this.query('post', url, data2, remap, options);
    }
    /**