0

I try to include lokiJS (locla json database) to my vue-electron app from a vue-cli-plugin-electron-builder!.

src/db/db.js

const path = require('path')
import * as loki from 'lokijs';
const dbPath = path.resolve('src/db/db.json')
let db = new loki(dbPath);
export default db

src/main.js

import db from './db/db'
Vue.prototype.$db = db

src/components/component.vue

created() {
    const db = this.$db;
    db.loadDatabase({}, () => {
      let rooms = db.getCollection("rooms");
      this.rooms = rooms.find({ activ: true });
    });
  }

If I work in dev mode all works fine but when I build electron production app is import db from './db/db' not include. Thank you!

4

1 回答 1

0

当您在构建保存在资源目录中的所有文件后以开发模式工作时。喜欢

                    app 
                     |-  dlls
                     |- app.exe
                     |- resources
                               |- app(folder)  all the JS files kept inside this.

但在产品的情况

                   app 
                     |-  dlls
                     |- app.exe
                     |- resources
                               |- app.asar  all the JS files kept inside this zip.

所以首先检查在哪里保存它以及如何尝试访问这个 db 文件。

希望它会奏效。

于 2019-05-02T12:16:14.310 回答