diff --git a/components/card/ArticleCard.vue b/components/card/ArticleCard.vue index d022be8..2e441f9 100644 --- a/components/card/ArticleCard.vue +++ b/components/card/ArticleCard.vue @@ -5,13 +5,11 @@ const props = defineProps<{ post: IPost }>() -const thumbUrl = computed(() => { - // 如果文章缩略图为空,则从本地随机获取默认缩略图 - props.post.fields.thumb.value = props.post.fields.thumb.value ? props.post.fields.thumb.value : getAssetURL( - `common/${Math.floor(Math.random() * (7 - 1 + 1)) + 1}.jpg` - ) - return props.post.fields.thumb.value -}) +const pid = useAsyncData('pid', async () => (Math.floor(Math.random() * (7 - 1 + 1)) + 1).toString()) + +const thumbUrl = computed(() => props.post.fields.thumb.value) + +const randomId = computed(() => pid.data.value!) @@ -21,8 +19,9 @@ const thumbUrl = computed(() => { :to="{name: 'article-cid', params: {cid: post.cid}}">
- +
diff --git a/components/card/ArticleDefaultImage.vue b/components/card/ArticleDefaultImage.vue new file mode 100644 index 0000000..53d2670 --- /dev/null +++ b/components/card/ArticleDefaultImage.vue @@ -0,0 +1,21 @@ + + + + + \ No newline at end of file