@@ -29,7 +29,6 @@ export default {
2929 components: { Common, NoteAbstract, TagList },
3030 data () {
3131 return {
32- posts: [],
3332 tags: [],
3433 currentTag: ' 全部' ,
3534 currentPage: 1 ,
@@ -39,18 +38,26 @@ export default {
3938 },
4039 computed: {
4140 // 时间降序后的博客列表
42- handlePosts () {
43- let posts = this .$site .pages
41+ posts () {
42+ const currentTag = this .currentTag
43+ let posts = []
44+
45+ if (currentTag !== ' 全部' ) {
46+ posts = this .$tags .map [currentTag].pages
47+ } else {
48+ posts = this .$site .pages
49+ }
50+
4451 posts = this ._filterPostData (posts)
4552 this ._sortPostData (posts)
53+ posts = posts .length == 0 ? [] : posts
54+ this ._setPage (1 )
4655 return posts
4756 }
4857 },
4958 created () {
5059 if (this .$tags .list .length > 0 ) {
51- const currentTag = this .$route .query .tag ? this .$route .query .tag : this .currentTag
52-
53- this .getPagesByTags (currentTag)
60+ this .currentTag = this .$route .query .tag ? this .$route .query .tag : this .currentTag
5461 }
5562 },
5663
@@ -60,27 +67,9 @@ export default {
6067
6168 methods: {
6269
63- async tagClick (currentTag ) {
64- await this .getPagesByTags (currentTag)
65- window .scrollTo (0 , 0 )
66- },
67-
68- // 根据分类获取页面数据
69- getPagesByTags (currentTag ) {
70+ tagClick (currentTag ) {
7071 this .currentTag = currentTag
71-
72- let posts = []
73- if (currentTag !== ' 全部' ) {
74- posts = this .$tags .map [currentTag].pages
75- this ._sortPostData (posts)
76- } else {
77- posts = this .handlePosts
78- }
79-
80- // reverse()是为了按时间最近排序排序
81- this .posts = posts .length == 0 ? [] : posts
82-
83- this ._setPage (1 )
72+ window .scrollTo (0 , 0 )
8473 },
8574
8675 getCurrentTag (tag ) {
0 commit comments