簡體   English   中英

[Vue 警告]:在 firebase/firestore 中登錄用戶時找不到元素:#app

[英][Vue warn]: Cannot find element: #app while logging in user in firebase/firestore

當我單擊一個按鈕調用 signIn function 時,firebase 登錄服務運行並且用戶成功登錄, then我在 function 中提醒了一條消息。之后在控制台上顯示,

[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>

主程序

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");
})

我的猜測是您在創建應用程序之前調用了 signIn() 方法。 這就是警告的原因。

嘗試在 created() 中調用方法,我認為警告會消失。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM