尝试启用离线持久性时,Firebase给出错误

时间:2020-03-26 20:23:04

标签: firebase google-cloud-firestore nuxt.js

我正在尝试使用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读取或向其写入可以很好

1 个答案:

答案 0 :(得分:1)

因此Nuxt同时具有服务器和客户端执行功能。如果您希望仅在客户端(使用javascript)执行某些操作,则必须将其包装在process.browser中。

var activity = Activator.CreateInstance<MainActivity>();
RedirectToActivity(activity, true);

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

如果您有一些html或组件,则必须将它们包装在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); } }); } 中,因为不建议使用no-ssr