1

https://github.com/vuejs/vue-resource

I want to add a global setup to Vue.http

Like this

$.ajaxSetup({
    complete: function(xhr, status) {
        if (xhr.status == '401') {
            delCookie('un');
            window.location.hash = '#/login';
        }
    }
});
1
  • 1
    Please describe what's not working Commented Aug 18, 2015 at 10:52

3 Answers 3

0

It looks like you should be able to access and set default options in Vue.http.options and Vue.http.headers. This appears to be their default values respectively:

{ // options
    method: 'get',
    params: {},
    data: '',
    xhr: null,
    jsonp: 'callback',
    beforeSend: null,
    crossOrigin: null,
    emulateHTTP: false,
    emulateJSON: false
}

var jsonType = {'Content-Type': 'application/json;charset=utf-8'};
{ // headers
    put: jsonType,
    post: jsonType,
    patch: jsonType,
    delete: jsonType,
    common: {'Accept': 'application/json, text/plain, */*'},
    custom: {'X-Requested-With': 'XMLHttpRequest'}
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

new Vue({
    http: {
        root: '/root',
        headers: {
            Authorization: ''
        }
    }
})

Comments

0

You need to use interceptors https://github.com/pagekit/vue-resource/blob/develop/docs/http.md

Example, in yout app.js, or main.js

Vue.http.interceptors.push((request, next) => {
        next((response) => {
            if (response.status === 403) {
                location.reload();
            }
        });
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.