pagekit / vue-resource

The HTTP client for Vue.js
MIT License
10.08k stars 1.6k forks source link

Do not send parameters with undefined to body #719

Open gewisser opened 5 years ago

gewisser commented 5 years ago

src\url\index.js:58

/**
 * Encodes a Url parameter string.
 *
 * @param {Object} obj
 */

Url.params = function (obj) {

    var params = [], escape = encodeURIComponent;

    params.add = function (key, value) {

        if (isFunction(value)) {
            value = value();
        }

        if (value === null) {
            value = '';
        }

        this.push(escape(key) + '=' + escape(value));
    };

    serialize(params, obj);

    return params.join('&').replace(/%20/g, '+');
};

Vue.http.options.emulateJSON = true;

It is a little uncomfortable when value equals undefined. A line is sent to the backend:

What is Expected?

body = param=1

What is actually happening?

body = param=1&param2=undefined&param3=undefined

youngkaneda commented 5 years ago

I could work on this.