【问题标题】:ES 6 modules reimportES6 模块导入
【发布时间】:2017-01-04 10:04:13
【问题描述】:

如果我从 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';

在这个例子中,我需要在我的 component.js 中重新导入 VueResource 吗?

如果不是,我不明白为什么我想在 component.js 中使用 vue ressource 时出错:

Cannot read property '$http' of undefined

component.js:

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


    }, (response) => {
        //failure

    });

【问题讨论】:

  • 你说component.jscomponent.vue。它是哪一个?你能展示更多的组件吗? this.$http 在里面执行什么?组件方法? console.log(this) 给你组件了吗?

标签: vue.js vue-resource vue-component


【解决方案1】:

imports 不会被继承。每个模块都需要导入它需要的所有资源。

【讨论】:

  • 在打算使用this.$http的组件中,在Vue中不需要importvue-resource。
  • @Roy-J 这是什么意思??
  • @mesqueeb 如果模块 c 导入模块 b,模块 b 导入模块 a,模块 c 需要模块 a 中的东西,模块 c 仍然需要导入模块 a。通过导入模块 b 并没有得到它。
猜你喜欢
  • 1970-01-01
  • 2018-12-09
  • 1970-01-01
  • 2015-08-13
  • 2014-02-06
  • 2016-04-09
  • 1970-01-01
  • 2017-06-29
  • 1970-01-01
相关资源
最近更新 更多