feat: 实现前后端数据交互功能
- 添加axios API服务模块,封装所有后端接口调用 - 修改各视图组件,移除模拟数据,改为从后端API获取真实数据 - 更新文章、留言板等页面,支持后端数据渲染 - 添加README_API.md文档,说明API调用方式 - 升级axios依赖版本至1.12.2
This commit is contained in:
@@ -1,15 +1,31 @@
|
||||
<template>
|
||||
<div id="allstyle">
|
||||
<div class="header">
|
||||
<h1>文章内容页面</h1>
|
||||
<h1>{{ article.title }}</h1>
|
||||
</div>
|
||||
<div class="article-content">
|
||||
<p>{{ article.content }}</p>
|
||||
</div>
|
||||
<p>通过传来的{{ urls }}向服务器发送请求获取相关文章的链接</p>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
<script setup>
|
||||
import { useRoute } from 'vue-router';
|
||||
import { articleAPI } from '@/axios/api'
|
||||
import { ref, onMounted } from 'vue'
|
||||
const article = ref({})
|
||||
const urls = useRoute().query
|
||||
// 从后端获取文章详情
|
||||
onMounted(() => {
|
||||
articleAPI.getArticleById(urls.articleid).then(res => {
|
||||
article.value = res.data
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
}).finally(() => {
|
||||
console.log("finally")
|
||||
})
|
||||
})
|
||||
|
||||
</script>
|
||||
<style>
|
||||
</style>
|
||||
Reference in New Issue
Block a user