[Vue 警告]:在 firebase/firestore 中登录用户时找不到元素:#app

Posted

技术标签:

【中文标题】[Vue 警告]:在 firebase/firestore 中登录用户时找不到元素:#app【英文标题】:[Vue warn]: Cannot find element: #app while logging in user in firebase/firestore 【发布时间】:2021-11-19 19:23:41 【问题描述】:

当我单击按钮调用 signIn 函数时,firebase 登录服务运行并且用户成功登录,并且我在 then 函数中提醒了一条消息。之后在控制台上显示,

[Vue warn]: Cannot find element: #app

现在,当我刷新页面时,消息随后从控制台发出。 那么第一次登录时它显示该消息的原因是什么?

signIn()
               
 firebase.auth().signInWithEmailAndPassword(this.email, this.password).then(()=>
       alert("logged in")
    ).catch(err=>
        this.error = true
        this.errorMsg = err.message
        )
      

index.html

<!DOCTYPE html>
<html lang="">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <title><%= htmlWebpackPlugin.options.title %></title>
  </head>
  <body>
    <noscript>
      <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without javascript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

main.js

import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import Vue2Editor from "vue2-editor";
import firebase from 'firebase/app';
import "firebase/auth"

Vue.use(Vue2Editor);

Vue.config.productionTip = false;

firebase.auth().onAuthStateChanged(()=>
    new Vue(
      router,
      store,
      render: (h) => h(App),
    ).$mount("#app");
)

【问题讨论】:

【参考方案1】:

我的猜测是您在创建应用程序之前调用了 signIn() 方法。这就是警告的原因。

尝试调用created()中的方法,我认为警告会消失。

【讨论】:

以上是关于[Vue 警告]:在 firebase/firestore 中登录用户时找不到元素:#app的主要内容,如果未能解决你的问题,请参考以下文章

Vue 组件按需 - [Vue 警告]:找不到元素

如何解决:[Vue 警告]:在 vue.js 2 上渲染组件时出错?

Firestore.settings() 要求它的第一个参数是对象类型,但它是一个自定义对象

[Vue 警告]:未定义属性或方法“$v”

Vue警告]:属性或方法“选项”未在实例上定义,但在render.Vue js问题期间引用

vueJS [Vue 警告]:计算属性“title”已在数据中定义