Javascript 如何修复与API通信时的404错误
我正在使用nuxt.js(前端)和laravel6(后端)API。Laravel应用程序正在运行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
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吗?谢谢您的评论。我哪里出错了?你能发布你的网络标签的截图吗?