使用 axios.post 无法在 web.php 中获取 url 并在控制台中显示 "The server has not found matching the requested URI"

Using axios.post it is unable to fetch url in web.php and showing"The server has not found matching the requested URI"in console

实际上我正在尝试使用 axios.post

克隆 Instagram 关注和关注

这是我的 FollowButton.vue

<template>
    <div >

   <button  class="btn btn-primary  " @click="followUser">Follow</button>



    </div>
</template>
<script>
    export default {
        props:['userId'],

        mounted() {
            console.log('Component mounted.')
        },

        methods:{
          followUser(){

             axios.post('/follow/'+ this.userId).then(response=>{

                 alert(response.data);
             });
          }
        }
    }
</script>

这是我的web.php。我希望 axios 到达这条路线并且 return 响应

success

Route::post('/follow/{user}', function(){

    return ['success'];
});

这是在我的 index.blade.php 中,单击它会将用户 ID 传递给 followbutton.vue

 <flw-button user-id="{{$user->id}}"></flw-button> </div>   

试一试:

<button class="btn btn-primary" type="submit" @click.prevent="followUser">Follow</button>