Skip to content

Commit c257bab

Browse files
committed
🎨 路由参数验证
1 parent 2e73c99 commit c257bab

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

pages/tag/_tagName.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,21 @@
2424
import reachBottom from '~/mixins/reachBottom'
2525
2626
export default {
27-
async asyncData({ app, params }) {
27+
async asyncData({ app, params, error }) {
2828
// 标签详情
2929
const tagInfo = await app.$api.getTagDetail({
3030
tagName: encodeURIComponent(params.tagName)
31-
}).then(res => res.s === 1 ? res.d : {})
31+
}).then(res => {
32+
if (res.s === 1) {
33+
return res.d
34+
} else {
35+
error({
36+
statusCode: 404,
37+
message: res.m
38+
})
39+
return {}
40+
}
41+
})
3242
// 标签下的文章
3343
const articleList = await app.$api.getTagEntry({
3444
tagId: tagInfo.id,

0 commit comments

Comments
 (0)