我有一个 Laravel 后端和 React 前端,我使用 sainttum 进行 SPA 身份验证,并使用 Axios 来发出请求。我使用 localhost ,后端位于 http://localhost:8000 ,前端位于 http://localhost:3000 。
这是我的前端代码:
const apiClient = axios.create({
baseURL: `http://localhost:8000`,
withCredentials: true,
});
let config = {
headers: {
'Content-Type': 'application/json'
},
}
export async function login(credentials: LoginCredentials) {
return apiClient.get('sanctum/csrf-cookie', config).then(response => {
apiClient.post('/api/v1/login', JSON.stringify(credentials));
});
}
Run Code Online (Sandbox Code Playgroud)
我的 api 中间件类看起来像这样
'api' => [
\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Session\Middleware\StartSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
'throttle:api',
],
Run Code Online (Sandbox Code Playgroud)
这些是我的圣所配置;
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf(
'%s%s',
'localhost,localhost:3000,localhost:3000/api/v1/login,127.0.0.1,127.0.0.1:8000,::1',
env('APP_URL') ? ','.parse_url(env('APP_URL'), PHP_URL_HOST) : ''
))), …Run Code Online (Sandbox Code Playgroud) 我有一个使用页面视图构建器构建的水平表单。我想知道如何在不使用滚动物理的情况下滚动到下一页。这是我的代码
import 'package:flutter/material.dart';
import 'package:flutter_repo/screens/login.dart';
import 'package:flutter_repo/utils/beziercontainer.dart';
class SignUpPage extends StatefulWidget {
SignUpPage({Key key, this.title}) : super(key: key);
final String title;
@override
_SignUpPageState createState() => _SignUpPageState();
}
class _SignUpPageState extends State<SignUpPage> {
PageController pageController;
@override
void initState() {
pageController = PageController(initialPage: 0);
super.initState();
}
@override
void dispose() {
pageController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body:
);
}
onNext(){
if (pageController.hasClients) {
pageController.animateToPage(2, duration: Duration(milliseconds: 300), curve: Curves.easeIn);
}
}
onComplete(){
}
Widget _registrationFields() {
return PageView( …Run Code Online (Sandbox Code Playgroud) 所以我正在为我的一个 React 项目编写测试,我只是决定使用模拟服务工作者来模拟我的 api 调用,并且我正在尝试模拟登录端点。所以我正在尝试模拟登录错误,其中我返回错误消息当输入与特定电子邮件不匹配时。给出下面的代码;
const server = setupServer(
rest.post("https://testlogin.com/api/v1/login", (req, res, ctx) => {
// the issue is getting the email from the request body something like the code just below
if (req.body["email"] != "test@example.com") {
ctx.status(401);
return res(
ctx.json({
success: false
})
);
}
})
);
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?有更好的方法吗?
我正在尝试将 cookie 键值与我从 laravel 后端的响应返回到我的前端,但我收到一个错误消息
Method Illuminate\Routing\ResponseFactory::withCookie does not exist.
Run Code Online (Sandbox Code Playgroud)
这是我的控制器。
public function login(UserLoginRequest $request)
{
if(Auth::attempt(['email' => $request->get('email'), 'password' => $request->get('password'), 'role' => 'user'])){
$user = Auth::user();
$success['token'] = $user->createToken('AppName')->accessToken;
$success['user'] = new AppUser($user);
return response()->WithCookie(cookie('token', $success['token'], $minute = 10))->json(['success' => $success], 200);
} else {
return response()->json(['errors']);
}
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我正在尝试创建一个自定义浮动底部导航栏,我创建了一个小部件并添加了边距以创建浮动效果,但它添加了白色背景。

我需要在没有白色背景的情况下创建它。这是我的代码;
Scaffold(
bottomNavigationBar: AnimatedBottomBar(
currentIcon: viewModel.currentIndex,
onTap: (int index) => viewModel.updateIndex(index),
icons: viewModel.icons,
),
body: viewModel.pages[viewModel.currentIndex],
);
Run Code Online (Sandbox Code Playgroud)
然后是动画底部栏
import 'package:flutter/material.dart';
import 'package:woneserve_updated_mobile_app/app/theming/colors.dart';
import 'package:woneserve_updated_mobile_app/models/icon_model.dart';
class AnimatedBottomBar extends StatelessWidget {
final int currentIcon;
final List<IconModel> icons;
final ValueChanged<int>? onTap;
const AnimatedBottomBar({
Key? key,
required this.currentIcon,
required this.onTap,
required this.icons,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
color: Colors.transparent,
child: Container(
margin: const EdgeInsets.all(40),
padding: const EdgeInsets.all(15),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: …Run Code Online (Sandbox Code Playgroud) 我试图从我的后端api返回产品并将其显示在我的前端页面上。当我执行* ngFor循环时,它给了我一个错误。这是我的代码。
我的后端API
data
0
name "perferendis"
totalPrice 323.76
rating 5
discount 43
href
link "http://localhost:8000/api/products/1"
1
name "non"
totalPrice 92.34
rating 3.5
discount 19
href
link "http://localhost:8000/api/products/2"
2
name "a"
totalPrice 246.76
rating 3
discount 38
href
"http://localhost:8000/api/products/3"
3
name "vitae"
totalPrice 537.57
rating "No rating yet"
discount 1
href
link "http://localhost:8000/api/products/4"
links
first "http://localhost:8000/api/products?page=1"
last "http://localhost:8000/api/products?page=3"
prev null
next "http://localhost:8000/api/products?page=2"
meta
current_page 1
from 1
last_page 3
path "http://localhost:8000/api/products"
per_page 20
to 20
total 60
Run Code Online (Sandbox Code Playgroud)
我的服务
getProducts(): Observable<any> …Run Code Online (Sandbox Code Playgroud) 我有一个 Laravel 应用程序(部署在 heroku 上),我在其中收到了500 Internal Server error.
当我检查我的日志时,我在标题中看到错误方法:
响应头名称“Access-Control-Allow-Origin”包含无效字符,中止请求
我有cors middleware以下代码:
public function handle($request, Closure $next)
{
header('Access-Control-Allow-Origin : *');
header('Access-Control-Allow-Headers : Content-type, X-Auth-Token, Authorization, Origin');
return $next($request);
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
当我尝试从我的 api 获取数据时,我在我的 angular 6 项目中收到此错误。这是我的 api json 文件;
{"data":
[{"category_name":"Women Ready Made","slug":null,"image_url":"education.jpg","products":
[{"productName":"Kampala
Shorts","description":"Beautiful Handwoven Kampala Shorts","imageUrl":"C:\\codes\\Tradsonline\\img\\image1.jpg","price":2500,"discount":10},{"productName":"Flowing White Agbada","description":"Flowing white agbada with beautiful design.","imageUrl":"C:\\codes\\Tradsonline\\img\\image3.jpg","price":22000,"discount":15}]},{"category_name":"Men's Ready Made","slug":null,"image_url":"education.jpg","products":[{"productName":"Ankara Jacket","description":"Ankara Jackets with pockets.","imageUrl":"C:\\codes\\Tradsonline\\img\\image2.jpg","price":5000,"discount":15},{"productName":"Women Ankara Gown","description":"Women Ankara gown with beautiful design.","imageUrl":"C:\\codes\\Tradsonline\\img\\image4.jpg","price":8000,"discount":0}]},{"category_name":"Ankara Gowns","slug":null,"image_url":"education.jpg","products":[]}]}
Run Code Online (Sandbox Code Playgroud)
这是我的服务
getCategories(): Observable<Category[]> {
return this.http.get(this.base_url + 'categories')
.pipe(map(res => {
return res.data; //this is where the error happens
}));
Run Code Online (Sandbox Code Playgroud)
这是我对我的服务的进口
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Product } from '../models/product';
import { …Run Code Online (Sandbox Code Playgroud)