nebula/pages/index.vue

57 lines
1.2 KiB
Vue
Raw Normal View History

2020-06-19 17:10:44 +08:00
<template>
<div>
2021-05-07 08:26:51 +08:00
<announcement-list :announcements="announcements"></announcement-list>
2020-06-22 17:13:42 +08:00
<article-list :articles="articles" @currentChange="currentChangeArticle"></article-list>
2020-06-19 17:10:44 +08:00
</div>
</template>
2020-06-22 17:13:42 +08:00
<script>
import ArticleList from '~/components/archive/list'
2021-05-07 08:26:51 +08:00
import AnnouncementList from '~/components/announcement/list'
import {mapState} from 'vuex';
2020-07-03 11:04:25 +08:00
export default {
name: 'Index',
2022-10-09 09:42:21 +08:00
fetch() {
let {store, query, error} = this.$nuxt.context
return Promise.all([
2021-05-07 08:26:51 +08:00
store.dispatch('article/fetchList', {page: query.page || 1}),
store.dispatch('article/fetchAnnouncementList', {page: query.page || 1})
])
},
watch: {
'$route'(to, from) {
if (from.query.page && to.query.page) {
this.$router.go()
}
}
},
components: {
2021-05-07 08:26:51 +08:00
AnnouncementList,
ArticleList
},
computed: {
...mapState({
2021-05-07 08:26:51 +08:00
articles: state => state.article.list.data,
announcements: state => state.article.announcements.data
})
},
methods: {
currentChangeArticle(page) {
this.$router.push({
name: 'index',
query: {
page: page
}
2020-08-02 00:25:44 +08:00
})
2020-06-22 17:13:42 +08:00
}
},
mounted() {
this.$store.commit('setActiveMenu', 'index')
2020-06-22 17:13:42 +08:00
}
}
2020-06-22 17:13:42 +08:00
</script>
2020-06-19 17:10:44 +08:00
<style>
</style>