vuex dispatch 无法修改状态

问题描述:

在electron-vue中,使用vuex,调用this.$store.dispatch("changeLogin");无法修改登录状态。

方法定义:

clipboard.png

修改登录状态:

clipboard.png

输出结果:

isLogin初始是false,调用this.$store.dispatch("changeLogin");后输出结果还是false。
clipboard.png

看到控制台这边有这个提示,是否有关?

Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)

clipboard.png

阅读 4.3k
2 个回答

Ran into this problem myself, I had to import the store inside of my electron index.js

The issue is with the createSharedMutations() from the vuex-electron package

src -> main -> index.js

import { app, BrowserWindow } from 'electron'

// Store must be imported for the shitty vuex-electron sharedMutations
/* eslint no-unused-vars: 0 */
import store from '../renderer/store'

/**
 * Set `__static` path to static files in production
 * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
 */
if (process.env.NODE_ENV !== 'development') {
  global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
}

let mainWindow
const winURL = process.env.NODE_ENV === 'development'
  ? `http://localhost:9080`
  : `file://${__dirname}/index.html`

function createWindow () {
  /**
   * Initial window options
   */
  mainWindow = new BrowserWindow({
    height: 563,
    useContentSize: true,
    width: 1000,
    titleBarStyle: 'hidden'
  })

  mainWindow.loadURL(winURL)

  mainWindow.on('closed', () => {
    mainWindow = null
  })
}

app.on('ready', createWindow)

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', () => {
  if (mainWindow === null) {
    createWindow()
  }
})

dispatch对应actions 可用于处理异步情况
commit对应mutations 修改都要通过mutations来修改