【问题标题】:Axios.get data from Mysql DB. Vue.js, Laravelaxios.get 来自 Mysql DB 的数据。 Vue.js,Laravel
【发布时间】:2020-10-21 04:10:50
【问题描述】:

我为“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();
    }

感谢一切。

【问题讨论】:

  • 在大括号前放一个@ 符号。否则它将充当 echo @{{post}}
  • @STA 控制台错误是Vue warn]: Property or method "post" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
  • 和 ``` Uncaught (in promise) 错误:请求失败,状态码 401

标签: javascript laravel vue.js axios


【解决方案1】:

你需要把axios响应放到de post

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-18
    • 2016-04-20
    • 1970-01-01
    • 2021-03-21
    • 2017-04-20
    • 1970-01-01
    • 2020-04-29
    • 1970-01-01
    相关资源
    最近更新 更多