dexie / Dexie.js

A Minimalistic Wrapper for IndexedDB
https://dexie.org
Apache License 2.0
11.69k stars 641 forks source link

I use Nuxt framework, using SSR rendering will appear UnhandledPromiseRejectionWarning: MissingAPIError: no t found with indexedDB API. #804

Open qq781548819 opened 5 years ago

qq781548819 commented 5 years ago

in nuxt.config.js file


 /*
   ** Plugins to load before mounting the App
   */
  plugins: [
     '@/plugins/vuetify',
    {src:"@/plugins/db/index",ssr:false},
     // {
     //   src: '~plugins/vue-infinite-loading',
     //   ssr: false
     // },
      '~/plugins/axios',
     {
       src: '~plugins/ga.js',
       ssr: false
     },
     '~/plugins/core.js'
   ],

in /db/index.js

import Novel from './novel'
import Source from './source'
import Chapter from './chapter'
import Content from './content'
const db = new Dexie("toyue");
db.version(1).stores({
  novels: "&novel,*author,cover,intro,status,major,last_time",
  sources: "&novel,*author,last_chapter,last_url,total,last_update,detail_url,&parse_url,prefix_url,domain,current_index", //当前观看的下标
  chapters: "&parse_url,*catalogue",
  contents: "&parse_url,content_url,content",
  origins: "&novel,*sources"
});
db.novels.mapToClass(Novel);
db.sources.mapToClass(Source);
db.chapters.mapToClass(Chapter);
db.contents.mapToClass(Content);

export default db
dfahlander commented 5 years ago

Dexie is dependant on the IndexedDB interface that is a W3C browser interface. IndexedDBShim could possibly be used on nodejs to emulate the same interface on node, using sqlite3 as storage. Not sure the status of that setup right now. Maybe more info here: https://github.com/axemclion/IndexedDBShim/issues/325.

Rednas83 commented 3 years ago

Perhaps not ideal but for nuxt/next/ssr a workaround/solution could be

See also this blog https://deltener.com/blog/common-problems-with-the-nuxt-client-only-component/ for more information.