【问题标题】:Getting Uncaught TypeError: ...default is not a constructor - from Vue component获取未捕获的 TypeError: ...default 不是构造函数 - 来自 Vue 组件
【发布时间】:2016-09-18 12:58:39
【问题描述】:

您好,我在 chrome 控制台中收到以下错误:

Uncaught TypeError: _firebase2.default is not a constructor

当我在 Fire.vue (webpack vue-loader) 组件中使用以下代码时:

var db = new Firebase(this.rootUrl)

这是我的 Fire.vue 的完整代码:

<template lang="jade">
  h2 Hello from: {{ component_name }}
</template>

<script>
import Vue from 'vue'
import Firebase from 'firebase'
Vue.prototype.$consoleLog = function (args) { console.log(args) }

export default {
  props: {
    rootUrl: {
      default: 'https://boiling-heat...', // here will be url of database
      type: String
    }
  },
  data () {
    return {
      component_name: 'Firebase component!'
    }
  },
  ready () {
    var db = new Firebase(this.rootUrl) // <- this causes error
    this.$consoleLog(db)
  }
}
</script>

这与我的rootUrl 属性无关,只是为了保持代码干净。我不确定这是由 Firebase 包中的错误引起的,还是我在为我的组件导入它时遗漏了什么。

【问题讨论】:

    标签: javascript firebase vue.js node-modules vue-loader


    【解决方案1】:

    is not a constructor 表示Firebase 对象不应使用new 关键字调用。

    快速浏览npm module 页面给出了以下 Fireabse 初始化示例:

    var firebase = require('firebase');
    var app = firebase.intializeApp({ ... });
    

    【讨论】:

    • 谢谢。我从firebase.googleblog.com/2016/04/… 得到了我的new Firebase 我将尝试来自官方npm 模块文档的代码,如果可行,将您的答案标记为已接受。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-03
    • 2020-09-17
    相关资源
    最近更新 更多