首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于REST的Laravel-Vue JS登录

基于REST的Laravel-Vue JS登录
EN

Stack Overflow用户
提问于 2022-09-28 18:13:34
回答 1查看 198关注 0票数 1

我用laravel的cusotm授权创建了这个登录系统,后端部分单独工作,因为我使用了相同的方法,以前没有任何问题,但是现在我已经尝试了vue,它给我的请求失败了422个不可处理的内容错误。

我的控制器:

代码语言:javascript
复制
public function loginn(Request $request){
   $request->validate([
    'name' => 'required',
    'password' => 'required',
   ]);
    $credentials = $request->only('name', 'password');
    if (Auth::attempt($credentials)) {
        // Authentication passed...
        return response()->json([
            'message' => 'login successfull',
        ]);
    }
    else{
        return response()->json([
            'message' => 'login failed',
        ]);
    }
 }

api页面:

Route::post('/login', [control::class, 'loginn']);

我的前额:

代码语言:javascript
复制
<template>
    <v-app id="inspire">
       <v-content>
          <v-container fluid fill-height>
             <v-layout align-center justify-center>
                <v-flex xs12 sm8 md4>
                   <v-card class="elevation-12">
                      <v-toolbar dark color="black">
                         <v-toolbar-title>Login form</v-toolbar-title>
                      </v-toolbar>
                      <v-card-text>
                         <v-form>
                            <v-text-field
                               prepend-icon="mdi-account"
                               name="name"
                               label="name"
                               type="text"
                            ></v-text-field>
                            <v-text-field
                               id="password"
                               prepend-icon="mdi-lock"
                               name="password"
                               label="Password"
                               type="password"
                            ></v-text-field>
                         </v-form>
                      </v-card-text>
                      <v-card-actions >
                         <v-spacer></v-spacer>
                         <div class="align-items-center">
                         <v-btn color="yellow" @click=login >Login</v-btn>
                        </div>
                      </v-card-actions>
        
                   </v-card>
                </v-flex>
             </v-layout>
          </v-container>
       </v-content>
    </v-app>
 </template>
 <script>
   import axios from 'axios';
   export default{
       data: () => ({
          name: '',
          password: ''
       }),
       methods: {
         async login(){
                try {
                    await axios.post('http://127.0.0.1:8000/api/login',
                    {
                        name: this.name,
                        password: this.password,
                      
                     });
                        this.$router.push('/');
                    
                } catch (error) {
                    console.log(error);
                }
            }}
       
   }
 </script>
EN

回答 1

Stack Overflow用户

发布于 2022-09-28 18:26:32

使用laravel护照与api授权。在拉拉护照的帮助下,您将生成一个令牌,并将此令牌传递给标题上的授权。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73886096

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档