javascript - axios.get 来自 Mysql DB 的数据。Vue.js,Laravel
问题描述
我为“writer”创建了其他 Vue.js 管理页面,我可以在其中从 mysql DB 帖子中删除数据帖子。在管理页面“管理员”数据响应并且一切正常。
我想要数据的帖子页面。
<template>
<div>
<h1>POOST</h1>
<section class="posts-page">
<div
v-for="post in posts"
:key="post.id"
/>
{{ post }}
</section>
</div>
</template>
<script>
export default {
data() {
return {
posts: []
}
},
created() {
axios.get('/api/posts/').then(console.table())
}
}
</script>
<style>
API PostController.php
public function index()
{
return Post::with('user')->latest('id')->get();
}
感谢一切。
解决方案
您需要将 axios 响应放到 de post
async created(){
const posts = await axios.get('/api/posts/');
this.posts = posts.data;
}
推荐阅读
- python - 有没有办法解决数据库错误?
- java - 从部署在公共端口上的 Angular 应用程序访问部署在私有端口上的 Rest API(面向 Internet)
- python - 根据方法向 API 发送请求
- influxdb - InfluxDB 无 GROUP BY 时间的连续查询
- javascript - 是否可以仅将 css 应用于由扩展程序打开的窗口?
- javascript - 编辑本地 .json 文件
- java - MySQL如何减少连接丢失的事务超时
- json - 如何从 SQL Server 2017 中的 JSON 字符串中获取键和值?
- html - 网格的单元格容器内的图像不是正方形
- python - 使用 Python 检测数据框中哪些列是分类的