新手如何从零开始搭建自己的博客系统: 门户管理-新增文章详情

ppylox
·6/3/2023·0 阅读
AI 摘要模型根据正文自动生成,仅供参考

文章详情是博客系统核心页面。新建详情页分两步:先创建 src/views/postDetail.vue 文件,用 Vue3 的 reactive 定义写死的标题和内容数据并渲染;再在 src/router/index.ts 中添加 /postDetail 路由,懒加载该组件。完成后访问对应地址即可看到无样式、数据写死的简单效果。

文章详情是整个博客系统最核心的页面,也是整个博客传递信息给读者的最近的地方。新建详情页面可以分为两个步骤,新增详情文件,新增路由,这也是所有新建页面的基本步骤。

src/views/postDetail.vue

<template>\n    <div class="page-list">\n        <div>{{ state.item.title }}</div>\n        <div>{{ state.item.content }}</div>\n    </div>\n</template>\n  \n<script lang="ts" setup>\nimport { reactive } from "vue";\nconst state = reactive({\n    item: {\n        title: "这是第一篇文章",\n        content: "这是www.dsiab.com网站上的第一篇文章内容"\n    },\n\n});\n\n</script>

在src/router/index.ts文件中添加详情路由

{\n      path: "/postDetail",\n      component: () => import("@/views/postDetail.vue"),\n    }

新增完成后打开一下地址可以看到一个简单的额效果,没有样式,数据也是写死的。

http://127.0.0.1:7910/#/postDetail


相关文章

评论 (0)

暂无评论,来写第一条吧