louischatriot / nedb

The JavaScript Database, for Node.js, nw.js, electron and the browser
MIT License
13.51k stars 1.03k forks source link

Insert data with electron-vue #553

Open florentsorel opened 6 years ago

florentsorel commented 6 years ago

Hi,

I use electron-vue and I would like to insert some data.

export default {
  name: 'choose-file',
  methods: {
    openFile () {
      this.$db.messages.insert({
        test: 'test'
      })
      this.$electron.ipcRenderer.send('openFile', this.$db)
    }
  }
}

It works but if I do the same things in my listener:

ipcMain.on('openFile', (event, data) => {
  data.messages.insert({
    test: 'foo'
  })
})

In this case it doesn't work and I don't know why. Someone can explain how to insert my data?

constneo commented 5 years ago

ipcMain.on('openFile', (event, data) => { data.messages.insert({ test: 'foo' }) })

data is not the database you're using, it's the value you send at the rendering end.