[Vuejs]-If vue-resource has option like jQuery.ajaxSetup();

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'}
}
πŸ‘€David K. Hess

0πŸ‘

Try this:

new Vue({
    http: {
        root: '/root',
        headers: {
            Authorization: ''
        }
    }
})
πŸ‘€kai.zhang

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();
            }
        });
    });
πŸ‘€cmnardi

Leave a comment