Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何修复与API通信时的404错误_Javascript_Laravel_Nuxt.js - Fatal编程技术网

Javascript 如何修复与API通信时的404错误

Javascript 如何修复与API通信时的404错误,javascript,laravel,nuxt.js,Javascript,Laravel,Nuxt.js,我正在使用nuxt.js(前端)和laravel6(后端)API。Laravel应用程序正在运行http://172.16.10.86:8000port和nuxt.js应用程序正在运行http://localhost:3000。我想使用nuxt.js应用程序在MySQL数据库中发送数据。当我从我的nuxt.js应用程序发送POST请求时,它会正确重定向,但不会在数据库中插入任何数据。在“网络”选项卡中,我发现一个404错误 methods:{ async regis

我正在使用nuxt.js(前端)和laravel6(后端)API。Laravel应用程序正在运行
http://172.16.10.86:8000
port和nuxt.js应用程序正在运行
http://localhost:3000
。我想使用nuxt.js应用程序在MySQL数据库中发送数据。当我从我的nuxt.js应用程序发送
POST
请求时,它会正确重定向,但不会在数据库中插入任何数据。在“网络”选项卡中,我发现一个404错误

       methods:{
        async register(){
        try {
        await this.$axios.post('/auth/register',this.form);
        } catch(e) {
            return;
        }

            this.$auth.login({data: this.form});

            this.$router.push({name:'index'});
        }
nuxt.config.js

auth: {
    strategies: { 
         local: { 
          endpoints:{
           login:{
      url: '/auth/login',method: 'post', propertyName: 'token'
    },
    user:{
      url:'me', method: 'get', propertyName: 'data'
    },
    logout:{
      url:'logout', method: 'get'
    }
  }
 } 
 },
 axios:{
   baseUrl:'http://172.16.10.86:8000/api'
 },

您需要为API服务器添加完整URL

 methods:{
    async register() {
    try {
    await this.$axios.post('http://172.16.10.86:8000/api/auth/register', this.form);
    } catch(e) {
        return;
    }

        this.$auth.login({data: this.form});

        this.$router.push({name:'index'});
    }

我相信你只是输入了axios配置


它应该是
baseURL
而不是
baseURL
。请查看。

您知道404表示找不到URL吗?谢谢您的评论。我哪里出错了?你能发布你的网络标签的截图吗?