美文网首页Electron
electron-vue,无法改变vuex状态

electron-vue,无法改变vuex状态

作者: 上帝与我同幻想 | 来源:发表于2018-12-03 11:40 被阅读7次

一、问题描述

在electron-vue中使用vuex,调用this.$store.dispatch("changeLogin");时,无法修改登录状态,调试了很久都没有看出问题在哪边。

store代码

const state = {
  isLogin: false
}

const getters = {
  isLogin(state) {
    return state.isLogin
  }
}

const mutations = {
  changeLogin(state) {
    state.isLogin = true
  }
}

const actions = {
  changeLogin(context) {
    context.commit("changeLogin")
  }
}

export default {
  state,
  getters,
  mutations,
  actions
}

调用修改状态的方法

console.log(this.$store.getters.isLogin);
console.log(this.$store);
this.$store.dispatch("changeLogin");
console.log(this.$store.getters.isLogin);

输出结果

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

控制台输出结果.png

二、解决方法

在GitHub的issue里搜了下,没有发现类似的问题,最后实在没办法,我就在segmentfault上提了这个问题,问题链接
得到的回答是 src/renderer/store/index.js中引用了createSharedMutations插件,在注释掉这个插件后,果然可以改变状态了。

import Vue from 'vue'
import Vuex from 'vuex'

import { createPersistedState, createSharedMutations } from 'vuex-electron'

import modules from './modules'

Vue.use(Vuex)

export default new Vuex.Store({
  modules,
  plugins: [
    createPersistedState(),
    // 注释这个插件的调用 
    //createSharedMutations()
  ],
  strict: process.env.NODE_ENV !== 'production'
})

问题是解决了,但还是不了解引起这个问题具体的原因,这个插件是用于多窗口共享状态的,去掉后应该会影响多窗口的传值,或许有其他的解决方案。

问题留待继续跟踪

相关文章

  • electron-vue,无法改变vuex状态

    一、问题描述 在electron-vue中使用vuex,调用this.$store.dispatch("chang...

  • Vue——Vuex状态管理

    ①State: 单一状态树,Vuex管理的状态对象,是唯一的。 定义的变量只能看到状态改变的结果,但是无法跟踪状态...

  • Vue扩展

    VueX HTTP是无状态的,跨页面的数据无法共享,但Vue是单页面应用,VueX可以实现数据共享; VueX的更...

  • vuex Demo 理解其用法

    1.安装 vuex vuex的使用 state 用来数据共享数据存储 mutation 用来注册改变数据状态 g...

  • Vuex-State、Getter、Mutation、Actio

    一、state(状态) #使用state在 Vue 组件中获取Vuex 状态 (不常用 & 不能改变数据),想要获...

  • vuex、mixin

    vuex状态管理 用来读取的状态集中放在store中;改变状态mutations(同步的);异步逻辑封装在acti...

  • vue 中使用vuex和localStorage保存登录状态

    需求:刷新页面,登录状态不会因此改变 首先说一下vuex和localStorage的区别 1.实质区别 vuex存...

  • vue 中使用vuex和localStorage保存登录状态

    需求:刷新页面,登录状态不会因此改变 首先说一下vuex和localStorage的区别 1.实质区别vuex存的...

  • Electron-vue引入vuex报错

    在Electron 9中,在未通过enableRemoteModule WebPreferences选项显式启用远...

  • vuex

    Vuex介绍: Vuex官网:http://vuex.vuejs.org/ Vuex是实现数据状态管理的技...

网友评论

    本文标题:electron-vue,无法改变vuex状态

    本文链接:https://www.haomeiwen.com/subject/mmtycqtx.html