Skip to content

Instantly share code, notes, and snippets.

@fpontef
Forked from anonymous/request.js
Created September 16, 2016 20:33
Show Gist options
  • Save fpontef/def02f0820dd3f51bc8e7e5e672596a0 to your computer and use it in GitHub Desktop.
Save fpontef/def02f0820dd3f51bc8e7e5e672596a0 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Sep 16, 2016.
    20 changes: 20 additions & 0 deletions request.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    const stringfy = (value) => JSON.stringify([value]);
    const stringfyAndTransformToObject = (value) => ({ object: stringfy(value) })

    const makeRequest = () => {
    const context = arguments[0] || this;
    const post = (url, data, options) => context.$http(url, stringfyAndTransformToObject(data), options);
    return { post };
    };

    const install = (VueInstance) => {
    Object.defineProperties(VueInstance.prototype, {
    $request: {
    get() {
    return makeLoader(this);
    },
    },
    });
    };

    export default { install };