pagekit / vue-resource

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

Http options don't work when included with Vue instance #717

Open websanova opened 5 years ago

websanova commented 5 years ago

I'm having issue with options.

When using Vue.http.options.root it's all good, when including with Vue instance it seems to be ignored.

Same as issue here:

https://github.com/pagekit/vue-resource/issues/487

Not sure why that was closed.

import Vue from 'vue'
import App from 'PAGES/Index.vue'

import http from './http'
import store from './store'
import router from './router'

import './config/icons.js'
import './config/plugins.js'
import './config/components.js'

Vue.config.productionTip = false

// Vue.http.options.root = 'https://testing123.com';

new Vue({
    el: '#app',
    http: {
        root: 'https://testing123.com'
    },
    store: store,
    router: router,
    render: h => h(App)
})
scottescue commented 5 years ago

This is broken for me as well. However I was able to monkey patch it by adding this mixin to my root component:

  Vue.mixin({
    beforeCreate() {
      if (!this.$options.http) {
        this.$options.http = this.$root.$options.http;
      }
    }
  });

I'm using:

Edit: simplifying mixin patch