nebula/pages/topic/_topic_uri.vue

65 lines
1.5 KiB
Vue
Raw Normal View History

2020-07-31 17:40:17 +08:00
<template>
<div class="topic-archive-page">
2020-08-01 00:39:29 +08:00
<topic-nav :currentTopic="defaultParams.topic_uri"></topic-nav>
2020-07-31 17:40:17 +08:00
<article-list :articles="articles" @currentChange="currentChangeArticle"/>
</div>
</template>
<script>
import ArticleList from '~/components/archive/list'
2020-08-02 00:25:44 +08:00
import {mapState} from 'vuex';
2020-07-31 17:40:17 +08:00
export default {
name: "topicArticleList",
components: {
ArticleList
},
2020-08-02 00:25:44 +08:00
validate({params, store}) {
2020-08-01 00:39:29 +08:00
if (params.topic_uri === 'news') {
return true;
}
2020-07-31 17:40:17 +08:00
return params.topic_uri && store.state.topic.data.some(
topic => topic.topicUri === params.topic_uri
)
},
2020-08-02 00:25:44 +08:00
fetch({store, params}) {
2020-07-31 17:40:17 +08:00
return store.dispatch('article/fetchList', params)
},
computed: {
2020-08-02 00:25:44 +08:00
...mapState({
articles: state => state.article.list.data
}),
2020-07-31 17:40:17 +08:00
currentTopic() {
2020-08-01 00:39:29 +08:00
if (this.$route.params.topic_uri === 'news') {
return true;
}
2020-07-31 17:40:17 +08:00
return this.$store.state.topic.data.find(
topic => topic.topicUri === this.$route.params.topic_uri
)
},
defaultParams() {
return {
topic_uri: this.$route.params.topic_uri
}
}
},
methods: {
currentChangeArticle(page) {
2020-08-02 00:25:44 +08:00
this.$store.dispatch('article/fetchList', {page: page, topic_uri: this.defaultParams.topic_uri})
2020-07-31 17:40:17 +08:00
}
},
mounted() {
this.$store.commit('setActiveMenu', 'topic');
},
created() {
if (!this.currentTopic) {
this.$router.back()
}
}
}
</script>
<style scoped>
</style>