首页 > 解决方案 > 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();
    }

感谢一切。

标签: javascriptlaravelvue.jsaxios

解决方案


您需要将 axios 响应放到 de post

async created(){  
const posts = await axios.get('/api/posts/');
this.posts = posts.data;
}

推荐阅读