add blog
This commit is contained in:
1 parent
36338ed0d7
commit
7fe8f5d154
96 files changed
+21326
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import { Module, VuexModule, Mutation } from 'vuex-module-decorators'
|
||||
import { DataType } from '../utils/build-api'
|
||||
|
||||
@Module({
|
||||
name: 'global',
|
||||
stateFactory: true,
|
||||
namespaced: true,
|
||||
})
|
||||
export default class GlobalModule extends VuexModule {
|
||||
hash: Record<DataType, Record<string, string>> = {
|
||||
posts: {},
|
||||
slides: {},
|
||||
}
|
||||
|
||||
tag: Record<string, number> = {}
|
||||
|
||||
@Mutation
|
||||
setHash (h: any) {
|
||||
this.hash = h
|
||||
}
|
||||
|
||||
@Mutation
|
||||
setTag (tag: any) {
|
||||
this.tag = tag
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Store, ActionTree } from 'vuex'
|
||||
import { initialiseStores } from '~/utils/store-accessor'
|
||||
import { apiHash } from '~/assets/util'
|
||||
|
||||
const initializer = (store: Store<any>) => initialiseStores(store)
|
||||
|
||||
export const actions: ActionTree<any, any> = {
|
||||
async nuxtServerInit ({ commit }) {
|
||||
const [
|
||||
hPosts,
|
||||
hSlides,
|
||||
tPosts,
|
||||
] = await Promise.all([
|
||||
apiHash('/build/hash/posts.json', Math.random().toString().substr(-5)),
|
||||
apiHash('/build/hash/slides.json', Math.random().toString().substr(-5)),
|
||||
apiHash('/build/tag/posts.json', Math.random().toString().substr(-5)),
|
||||
])
|
||||
|
||||
commit('global/setHash', {
|
||||
posts: JSON.parse(hPosts),
|
||||
slides: JSON.parse(hSlides),
|
||||
})
|
||||
commit('global/setTag', JSON.parse(tPosts))
|
||||
},
|
||||
}
|
||||
|
||||
export const plugins = [initializer]
|
||||
export * from '~/utils/store-accessor'
|
||||
Reference in new issue
Block a user