Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.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
Php Laravel 6-未找到路线桩_Php_Vue.js_Nuxt.js - Fatal编程技术网

Php Laravel 6-未找到路线桩

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中 在我的控制器中 我将感谢你的帮

我正在尝试在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使用8000
http://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);