-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88a0735
commit cc3a943
Showing
2 changed files
with
86 additions
and
53 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
packages/home/src/components/home/article/article-list.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<template> | ||
<div class="freyja-article-list"> | ||
<article | ||
v-for="article in articles" | ||
:key="article._id" | ||
> | ||
<h3 class="freyja-article-title"> | ||
<router-link :to="{name: 'article', params: {id: article._id}}"> | ||
{{ article.title }} | ||
</router-link> | ||
</h3> | ||
<div class="freyja-article-info freyja-article-time"> | ||
<hr> | ||
<span class="time"><i class="el-icon-time" /> {{ formatDate(article.createdAt) }}</span> | ||
<span class="comments"> | ||
<i | ||
v-if="article.commentCount === 0" | ||
class="fa fa-comments" | ||
>并没有评论</i> | ||
<i | ||
v-else | ||
class="fa fa-comments" | ||
>有{{ article.commentCount }}条评论</i> | ||
</span> | ||
</div> | ||
<div class="freyja-article-summary freyja-article-content"> | ||
<div v-html="article.summary" /> | ||
</div> | ||
<hr> | ||
</article> | ||
</div> | ||
</template> | ||
<script lang="ts" setup> | ||
import lozad from 'lozad' | ||
import prismjs from 'prismjs' | ||
import {onMounted, onUpdated, ref} from 'vue' | ||
import {IArticle} from '../../../store/home.ts' | ||
const props = defineProps<{ | ||
articles: IArticle[] | ||
}>() | ||
const articles = ref(props.articles) | ||
onMounted(() => { | ||
highlight() | ||
const observer = lozad() | ||
observer.observe() | ||
}) | ||
onUpdated(() => { | ||
highlight() | ||
}) | ||
function highlight(): void { | ||
prismjs.highlightAll() | ||
} | ||
function formatDate(date: Date | string): string { | ||
if (typeof date === 'string') { | ||
date = new Date(date) | ||
} | ||
return date.toLocaleString() | ||
} | ||
</script> | ||
<style lang="scss"> | ||
.freyja-article-pager-prev { | ||
float: left; | ||
width: 300px; | ||
max-width: 40%; | ||
} | ||
.freyja-article-pager-next { | ||
float: right; | ||
width: 300px; | ||
max-width: 40%; | ||
} | ||
.freyja-article-info { | ||
.time { | ||
margin-right: 20px; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters