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'
export default {
name: "topicArticleList",
components: {
ArticleList
},
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
)
},
fetch({ store, params }) {
return store.dispatch('article/fetchList', params)
},
computed: {
articles() {
return this.$store.state.article.list.data
},
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) {
this.$store.dispatch('article/fetchList', {page: page,topic: this.currentTopic})
}
},
mounted() {
this.$store.commit('setActiveMenu', 'topic');
2020-08-01 00:39:29 +08:00
console.log(this.defaultParams)
2020-07-31 17:40:17 +08:00
},
created() {
if (!this.currentTopic) {
this.$router.back()
}
}
}
</script>
<style scoped>
</style>