Firebase尝试启用脱机持久性时出现错误

问题描述 投票:0回答:1

我正在尝试使用Nuxt.js在Web应用程序上启用离线持久性。但是,我得到一个错误:

Error enabling offline persistence. Falling back to persistence disabled: FirebaseError: [code=unimplemented]: 
This platform is either missing IndexedDB or is known to have an incomplete implementation. 
Offline persistence has been disabled.

我在firebase.js目录中plugins中的代码是:

import firebase from 'firebase/app'
import 'firebase/firestore'

const config = {
        apiKey: '',
        authDomain: '',
        databaseURL: '',
        projectId: '',
        storageBucket: '',
        messagingSenderId: '',
        appId: '',
        measurementId: ''
}
firebase.initializeApp(config)

const fireDb = firebase.firestore();
fireDb.enablePersistence()
  .catch(function(err) {
      if (err.code == 'failed-precondition') {
          // Multiple tabs open, persistence can only be enabled
          // in one tab at a a time.
          // ...
          console.log(err.code);
      } else if (err.code == 'unimplemented') {
          // The current browser does not support all of the
          // features required to enable persistence
          // ...
          console.log(err.code);
      }
  });



export{fireDb}

如何解决此错误?应该注意的是,从Firestore读取或向其写入可以正常工作

firebase google-cloud-firestore nuxt.js
1个回答
0
投票

因此Nuxt同时具有服务器端和客户端端的执行权。如果您只想在客户端执行某些操作,则必须将其包装在process.browser中。

if(process.browser){
fireDb.enablePersistence()
  .catch(function(err) {
      if (err.code == 'failed-precondition') {
          // Multiple tabs open, persistence can only be enabled
          // in one tab at a a time.
          // ...
          console.log(err.code);
      } else if (err.code == 'unimplemented') {
          // The current browser does not support all of the
          // features required to enable persistence
          // ...
          console.log(err.code);
      }
  });
}

请注意,如果您要初始化Firebase云消息传递,则必须采用相同的方法。

© www.soinside.com 2019 - 2024. All rights reserved.