first commit
This commit is contained in:
63
store/index.js
Normal file
63
store/index.js
Normal file
@ -0,0 +1,63 @@
|
||||
export const state = () => ({
|
||||
counter: 0,
|
||||
newComments: [],
|
||||
hotArticle: [],
|
||||
categorys: [],
|
||||
tags: []
|
||||
})
|
||||
|
||||
export const mutations = {
|
||||
increment(state) {
|
||||
state.counter++
|
||||
},
|
||||
setLeftDatas(state, data) {
|
||||
const NewComments = data[0]
|
||||
const HotArticle = data[1]
|
||||
const terms = data[2]
|
||||
for (const n in NewComments) {
|
||||
NewComments[n].comment_date = this.$moment(NewComments[n].comment_date).format('YYYY-MM-DD')
|
||||
}
|
||||
|
||||
state.newComments = NewComments
|
||||
for (const n in HotArticle) {
|
||||
HotArticle[n].post_modified = this.$moment(HotArticle[n].post_modified).format('MMM Do YY')
|
||||
}
|
||||
state.hotArticle = HotArticle
|
||||
|
||||
const categorys = []
|
||||
const tags = []
|
||||
|
||||
for (const n in terms) {
|
||||
if (terms[n].term_taxonomy.taxonomy === 'category') {
|
||||
categorys.push(terms[n])
|
||||
} else {
|
||||
tags.push(terms[n])
|
||||
}
|
||||
}
|
||||
|
||||
state.categorys = categorys
|
||||
state.tags = tags
|
||||
}
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
async nuxtServerInit({ state, commit }, { $axios }) {
|
||||
if (state.tags.length === 0) {
|
||||
try {
|
||||
const datas = await Promise.all([
|
||||
$axios.$get('/public/comments/list'),
|
||||
$axios.$get('/public/article/hot'),
|
||||
$axios.$get('/public/terms/all')
|
||||
])
|
||||
|
||||
for (const n in datas) {
|
||||
datas[n] = datas[n].result
|
||||
}
|
||||
|
||||
commit('setLeftDatas', datas)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user