Vue.component("axios", {
template: '<template>     <div>         <vv-notice ref=\'notice\'></vv-notice>     </div> </template>',
data :function () {
    return { axios: undefined };
},
methods :{
    send: function (token, subject, params, only_this_params) {
        let self = this;
        let params_beauty = only_this_params && only_this_params.length > 0 ? {} : params;
        if (only_this_params && only_this_params.length > 0) {
            for (var prop in params) {
                if (only_this_params.some(f => f === prop)) {
                    params_beauty[prop] = params[prop];
                }
            }
        }
        this.axios.post('', {
            token: token,
            subject: subject,
            params: params_beauty
        }).then(function (response) {
            self.on_reply(response);
        }).catch(function (error) {
            self.on_error(error, subject, params_beauty);
        });
    },
    on_error: function (error, subject, params) {
        if (!error) {
            this.$refs.notice.error('backend return empty error');
            return;
        }
        this.$refs.notice.error(error);
        this.$emit('error', {
            subject: subject,
            params: params,
            error: error
        });
    },
    on_reply: function (response) {
        if (!response || !response.data || !response.data.subject) {
            this.$refs.notice.error('backend return empty answer');
            return;
        }
        this.$emit('reply', response.data);
    }
},
mounted :function () {
    this.$nextTick(function () {
        this.axios = axios.create();
        this.axios.defaults.withCredentials = true;
    });
}
})