【问题标题】:Vuefire with Vue 3 throwing Vue.use error带有 Vue 3 的 Vuefire 抛出 Vue.use 错误
【发布时间】:2021-03-02 11:54:20
【问题描述】:

所以我创建了一个 vue 应用程序并从 vue 模块导入了 Vue 但我收到了这个错误

ERROR in src/main.ts:4:5
TS2339: Property 'use' does not exist on type 'typeof import("/data/data/com.termux/files/home/ishankbg.tech/node_modules/vue/dist/vue")'.
    2 | import App from './App.vue'
    3 | import { firestorePlugin } from 'vuefire';
  > 4 | Vue.use(firestorePlugin);
      |     ^^^
    5 | createApp(App).mount('#app');
    6 |

我在我的 vue 应用程序中使用打字稿。 我使用@vue/cli 生成了项目。 我想使用 vuefire 的 firestorePlugin。

我正在使用 Vue3 这是源代码

import Vue, { createApp } from 'vue'
import App from './App.vue'
import { firestorePlugin } from 'vuefire';
Vue.use(firestorePlugin);
createApp(App).mount('#app');

我不确定是什么导致了这个错误

【问题讨论】:

    标签: javascript typescript vue.js vuejs3 vuefire


    【解决方案1】:

    Vuefire 在 Vue 3 中尚不支持。从主页:

    注意:此版本目前支持 Vue 2 和 Firebase 7。对 Vue 3 / Composition API 和 Firebase 8 的支持正在开发中。

    Vue.use 是 Vue 2 安装插件的方式。一旦 Vuefire 支持 Vue 3,请使用 app.use 而不是 Vue.use。在 Vue 3 中,Vue 不是来自 "vue" 包的有效导出:

    import { createApp } from 'vue'
    import App from './App.vue'
    import { firestorePlugin } from 'vuefire';
    
    const app = createApp(App);
    app.use(firestorePlugin);
    app.mount("#app");
    

    【讨论】:

    • 感谢@dan,但您知道如何在单个组件上使用 Vue.use (app.use) 插件吗?
    • @Vixson 并不是这样。插件基本上只是在加载应用程序时运行的全局级函数,所以也许你需要重新考虑你想要做什么。 v3.vuejs.org/guide/plugins.html
    • 好的@Dan 谢谢,我已经明白了。只是从 Vue 2 迁移到 Vue 3。我得到了一些突破性的变化。在 Vue 2 上,我通常只在我需要的组件上导入我需要的插件。现在在 Vue 3 上,我只是迷失了如何去做。
    猜你喜欢
    • 2021-11-15
    • 2021-10-24
    • 2015-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-03
    • 2023-02-03
    相关资源
    最近更新 更多