Firebase выдает ошибку при попытке включить автономное сохранение - PullRequest
0 голосов
/ 26 марта 2020

Я пытаюсь включить автономное сохранение в веб-приложении с Nuxt.js. Однако я получаю ошибку:

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}

Как я могу исправить эту ошибку? Следует отметить, что чтение или запись в пожарный магазин работает нормально

1 Ответ

0 голосов
/ 04 апреля 2020

Итак, у 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, вам придется использовать тот же подход. ,

...