diff --git a/packages/playground/ssr/src/main.js b/packages/playground/ssr/src/main.js index d4f9420abeee07124affe417788654a22fe57700..0b8a7832a46c55bf3ab3693fe9188993deffb873 100644 --- a/packages/playground/ssr/src/main.js +++ b/packages/playground/ssr/src/main.js @@ -1,6 +1,6 @@ import { createSSRApp } from 'vue' import App from './App.vue' -import createStore from './store/index' +import createStore from './store' export function createApp() { const app = createSSRApp(App) diff --git a/packages/playground/ssr/src/store/index.js b/packages/playground/ssr/src/store/index.js new file mode 100644 index 0000000000000000000000000000000000000000..ba43be23b6019b9bbf020999cfd374de92345a6e --- /dev/null +++ b/packages/playground/ssr/src/store/index.js @@ -0,0 +1,35 @@ +import { createStore } from 'vuex' + +// mock +function fetchItem(id) { + return new Promise((resolve) => { + setTimeout(() => { + resolve({ + id, + title: 'title' + id, + }) + }, 300) + }) +} + +export default () => { + return createStore({ + state() { + return { + items: {}, + } + }, + actions: { + fetchItem({ commit }, id) { + return fetchItem(id).then((item) => { + commit('setItem', { id, item }) + }) + }, + }, + mutations: { + setItem(state, { id, item }) { + state.items[id] = item + }, + }, + }) +}