Php Laravel 6-未找到路线桩
我正在尝试在NuxtJS中实现Php Laravel 6-未找到路线桩,php,vue.js,nuxt.js,Php,Vue.js,Nuxt.js,我正在尝试在NuxtJS中实现注册用户。然而,我遇到的问题如下 vendor/laravel/framework/src/illumb/Routing/RouteCollection.php 在我的api路线中 我尝试将其更改为get方法,并通过127.0.0.1:8000/api/register访问它,它的工作非常好 我还是不知道,为什么我得到了这个帖子http://127.0.0.1:3000/api/register 404(未找到) 在我的Nuxtjs中 在我的控制器中 我将感谢你的帮
注册用户
。然而,我遇到的问题如下
vendor/laravel/framework/src/illumb/Routing/RouteCollection.php
在我的api路线中
我尝试将其更改为get方法
,并通过127.0.0.1:8000/api/register访问它,它的工作非常好
我还是不知道,为什么我得到了这个帖子http://127.0.0.1:3000/api/register 404(未找到)
在我的Nuxtjs中
在我的控制器中
我将感谢你的帮助。
谢谢。您正在使用3000端口http://127.0.0.1:3000/api/register
在axios中,但laravel使用8000http://127.0.0.1:8000/api/register
您必须在NuxtJS应用程序中建立API基本URL
原因是您的NuxtJS应用程序将默认设置为它自己的基本URL
但您必须为LaravelAPI配置后端URL
例如
试试这个
await this.$axios.post(`http://127.0.0.1:8000/api/register`, this.auth);
async registerUser() {
try {
await this.$axios.post(`api/register`, this.auth);
await this.$auth.login({
data: {
email: this.auth.email,
password: this.auth.password,
}
})
.then(res => {
console.log(res);
this.loading = false
// this.$router.push(`/auth/login`);
})
.catch(err => {
this.loading = false
this.$refs.form.validate(err.response.data.errors)
console.log(err.response);
})
} catch(e) {
// statements
console.log(e);
}
public function register(Request $request)
{
$request->validate([
'name' => 'required',
'email' => 'required|email',
'password' => 'required|between:6, 25',
]);
$user = new User();
$user->name = $request->name;
$user->email = $request->email;
$user->password = bcrypt($request->password);
$user->save();
return response()->json(['registered' => true ]);
}
await this.$axios.post(`http://127.0.0.1:8000/api/register`, this.auth);