From 8c89a09f0669e04027198874cbd9fd5e354eff97 Mon Sep 17 00:00:00 2001 From: zgqq Date: Fri, 15 Mar 2019 17:34:27 +0800 Subject: [PATCH] fix(vuex): dispatch action(#https://github.com/SimulatedGREG/electron-vue/issues/733) --- src/main/index.js | 3 +- src/renderer/App.vue | 46 ++++---- src/renderer/components/ConfirmPage.vue | 108 +++++++++++------- .../LandingPage/SystemInformation.vue | 62 +++++----- src/renderer/main.js | 1 + src/renderer/store/index.js | 5 +- src/renderer/store/modules/ConfirmPage.js | 24 ++++ src/renderer/store/modules/Counter.js | 6 +- 8 files changed, 156 insertions(+), 99 deletions(-) create mode 100644 src/renderer/store/modules/ConfirmPage.js diff --git a/src/main/index.js b/src/main/index.js index 24121d5..b206664 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1,6 +1,7 @@ 'use strict' -import { app, BrowserWindow, globalShortcut, clipboard } from 'electron' +import { app, BrowserWindow, globalShortcut } from 'electron' +import '../renderer/store' /** * Set `__static` path to static files in production diff --git a/src/renderer/App.vue b/src/renderer/App.vue index 0058f7c..9c2645a 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -5,29 +5,33 @@ diff --git a/src/renderer/components/ConfirmPage.vue b/src/renderer/components/ConfirmPage.vue index 5201e90..dd5d272 100644 --- a/src/renderer/components/ConfirmPage.vue +++ b/src/renderer/components/ConfirmPage.vue @@ -1,59 +1,83 @@ diff --git a/src/renderer/components/LandingPage/SystemInformation.vue b/src/renderer/components/LandingPage/SystemInformation.vue index 1bd5c91..64e2a1f 100644 --- a/src/renderer/components/LandingPage/SystemInformation.vue +++ b/src/renderer/components/LandingPage/SystemInformation.vue @@ -31,43 +31,45 @@ diff --git a/src/renderer/main.js b/src/renderer/main.js index 92ee470..b2ebabf 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -14,6 +14,7 @@ Vue.config.productionTip = false // console.log('nice') // }) /* eslint-disable no-new */ +store.dispatch('nice') new Vue({ components: { App }, router, diff --git a/src/renderer/store/index.js b/src/renderer/store/index.js index e946d8c..a3e5b48 100644 --- a/src/renderer/store/index.js +++ b/src/renderer/store/index.js @@ -9,9 +9,6 @@ Vue.use(Vuex) export default new Vuex.Store({ modules, - plugins: [ - createPersistedState(), - createSharedMutations() - ], + plugins: [createPersistedState(), createSharedMutations()], strict: process.env.NODE_ENV !== 'production' }) diff --git a/src/renderer/store/modules/ConfirmPage.js b/src/renderer/store/modules/ConfirmPage.js new file mode 100644 index 0000000..4409124 --- /dev/null +++ b/src/renderer/store/modules/ConfirmPage.js @@ -0,0 +1,24 @@ +const state = { + imgUrl: 'https://aliook' +} + +const mutations = { + CHANGE_IMG_URL (state, payload) { + console.log('mutations log') + state.imgUrl = 'ok' + } +} + +const actions = { + changeImgUrl ({ commit }, payload) { + // do something async + console.log('aaaaa') + commit('CHANGE_IMG_URL', payload) + } +} + +export default { + state, + mutations, + actions +} diff --git a/src/renderer/store/modules/Counter.js b/src/renderer/store/modules/Counter.js index 44a8ab4..5f92fc5 100644 --- a/src/renderer/store/modules/Counter.js +++ b/src/renderer/store/modules/Counter.js @@ -12,9 +12,13 @@ const mutations = { } const actions = { - someAsyncTask ({ commit }) { + add ({ commit }) { // do something async + console.log('aaaa') commit('INCREMENT_MAIN_COUNTER') + }, + nice ({ commit }) { + console.log('nice') } }