|
@@ -6,12 +6,14 @@ import type { PostDetail } from '@/models'
|
|
import PostDetailContent from '@/components/PostDetailContent.vue'
|
|
import PostDetailContent from '@/components/PostDetailContent.vue'
|
|
|
|
|
|
function parseId() {
|
|
function parseId() {
|
|
- let targetPostId = router.currentRoute.value.params['id']
|
|
|
|
|
|
+ console.log(router.currentRoute.value.params) // 为什么输出为空
|
|
|
|
+ let targetPostId = router.currentRoute.value.query['id']
|
|
if (Array.isArray(targetPostId)) {
|
|
if (Array.isArray(targetPostId)) {
|
|
if (targetPostId.length) {
|
|
if (targetPostId.length) {
|
|
targetPostId = targetPostId[0]
|
|
targetPostId = targetPostId[0]
|
|
} else return undefined
|
|
} else return undefined
|
|
}
|
|
}
|
|
|
|
+ if (!targetPostId) return undefined;
|
|
const id = Number(targetPostId)
|
|
const id = Number(targetPostId)
|
|
if (isNaN(id)) {
|
|
if (isNaN(id)) {
|
|
return undefined
|
|
return undefined
|
|
@@ -28,15 +30,21 @@ async function freshData() {
|
|
if (res.code == 200) {
|
|
if (res.code == 200) {
|
|
postDetail.value = res.data
|
|
postDetail.value = res.data
|
|
return true
|
|
return true
|
|
- } else return false
|
|
|
|
|
|
+ } else {
|
|
|
|
+ console.error(res.msg)
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
postId = parseId() ?? NaN
|
|
postId = parseId() ?? NaN
|
|
- if (!postId) {
|
|
|
|
|
|
+ if (isNaN(postId)) {
|
|
router.push('/')
|
|
router.push('/')
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ console.log(postId)
|
|
|
|
+
|
|
freshData().then((res) => {
|
|
freshData().then((res) => {
|
|
if (!res) router.push('/')
|
|
if (!res) router.push('/')
|
|
})
|
|
})
|