Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从主进程更新Vuex存储_Javascript_Vue.js_Frontend_Electron - Fatal编程技术网

Javascript 从主进程更新Vuex存储

Javascript 从主进程更新Vuex存储,javascript,vue.js,frontend,electron,Javascript,Vue.js,Frontend,Electron,如何通过从主进程提交内容来更新vuex存储?例如: 在主线程中: import store from ../store ipc.on('someevent', (event, args) => { // do stuff with args store.commit('update-things') }) 在渲染器中,使用这些修改更新组件 编辑: 实数代码: main.js import store from '../store' const {ipcMain} = requi

如何通过从主进程提交内容来更新vuex存储?例如:

在主线程中:

import store from ../store

ipc.on('someevent', (event, args) => {
    // do stuff with args
store.commit('update-things')
})
在渲染器中,使用这些修改更新组件

编辑: 实数代码:

main.js

import store from '../store'
const {ipcMain} = require('electron')
const WebTorrent = require('webtorrent')
const client = new WebTorrent()

ipcMain.on('addMagnet', (event, arg) => {
   client.add(arg, function (torrent) {
   var files = []
    torrent.files.forEach(function (file) {

    files.push({
        title: file.name,
        torrent: torrent.infoHash,
        index: torrent.files.indexOf(file),
        duration: '--:--'
    })
   })
  store.commit('addSongs', files)
})
存储突变就像:

addSongs (state, newSongs) {
    newSongs.forEach(function (song) {
      state.songs.push(song)
    })
}
存储在main.js的不同目录中(如果有帮助的话)

使用存储的组件是:

**by this component:

     <template>
      <div id="playlist">
        <div
          is="song"
          v-for="song in songs"
          v-bind:title="song.title"
          v-bind:torrent="song.torrent"
          v-bind:index="song.index">
    </div>
  </div>

</template>

<script>
import Song from './SongList/Song'

export default {
  name: 'playlist',
  components: { Song },
  computed: {
    songs () {
      return this.$store.getters.songs
    }
  }
}
</script>
**通过此组件:
从“./SongList/Song”导入歌曲
导出默认值{
名称:'播放列表',
组件:{Song},
计算:{
歌曲(){
退回此。$store.getters.songs
}
}
}

我知道这是一个老话题,但对于未来的搜索者,您可以使用
vuex electron
从主线程发送到商店


所有这些看起来都是正确的,什么东西没有按预期工作?当我提交html没有更改的更新内容时,如果有帮助的话,我可以更新真实的代码。是的,你需要向我们展示相关的代码。我认为这不会起作用。基本上,您要处理两个独立的存储,因为主进程与渲染器不同。