帖子未显示,因为我在 laravel 中使用 vue.js 但它给出了 404 错误

Posts are not shown, as I am using vue.js in laravel but it gives the 404 error

这是我的 app.js 文件,其中响应显示在控制台上,但它给出了错误。不知道为什么

require('./bootstrap');

window.Vue = require('vue');

Vue.component('posts', require('./components/posts.vue'));

const app = new Vue({
    el: '#app',
    data:{
        blog:{},
    },
    mounted(){
        axios.post('/getPosts')
          .then(response => {
            this.blog = response.data.data
            //console.log(response);
          })
          .catch(function (error) {
            console.log(error);
          });
    }
});

这是我的路线,它显示 getPosts 的页面,但未显示

Route::post('getPosts','PostController@getAllPosts');

这是我的posts.vue,其中包含帖子模板

<template>
    <div class="post-preview">
        <a href="slug">
            <h2 class="post-title">
                {{ title }}
            </h2>
            <h3 class="post-subtitle">
                {{ subtitle }}
            </h3>
        </a>
        <p class="post-meta">Posted by
            <a href="#">Start Bootstrap</a>
                {{ created_at }}  
            <a href="">
                <small>0</small>
                <i class="fa fa-thumbs-up" aria-hidden="true"></i>
            </a>
        </p>
    </div>
</template>

<script>
    export default {
       props:[
        'title','subtitle','created_at'
       ]
    }
</script>

在我 blog.blade.php 写这篇文章的时候

<posts 
     v-for='value in blog'
    :title='value.title'
    :subtitle='value.subtitle'
    :created_at='value.created_at'     
></posts>

我没有看到这个页面,我不知道为什么!我收到了这个错误。 POST http://localhost:8080/getPosts 404(未找到) 我还附上了错误的图片

我想我可能已经找到了问题所在。您的网络服务器配置与您的请求不兼容。

看起来像是您的服务器期望 getPosts 位于 website/public 端点 将 Axios 调用更改为 axios.post('/website/public/getPosts')axios.post('getPosts') 应该可以解决 404 问题。

您还可以更改您的配置,使 http://localhost:8080 指向您的 Laravel public 目录;这可能更好地反映生产环境。