Search code examples
vue.jsvue-resourcevue-component

ES 6 modules reimport


If i import my modules from my main.js :

import Vue from 'vue'
import store from './vuex/store'
import VueResource from 'vue-resource'

Vue.use(VueResource);

import Component from './components/component.vue';

In this example, do i need to reimport VueResource in my component.js ?

If not i don't understand why i have an error when i want to use vue ressource in my component.js :

Cannot read property '$http' of undefined

component.js :

this.$http.get('http://ajaxurl.test').then((response) => {
        // success callback


    }, (response) => {
        //failure

    });

Solution

  • imports are not inherited. Each module needs to import all the resources it needs.