我有这个反应组件
import React, { useState, useEffect } from 'react';
import axios from "axios";
import "../../css/driversStandings.css";
function DriversStandingsComponent() {
const [data, setData] = useState([]);
var row = 1;
useEffect(() => {
axios.get("http://localhost:4000/api/standings").then(res => {
const driversChampionshipData = res.data[0].DriversChampionship
setData(driversChampionshipData);
console.log(data)
})
});
return (
//Here I return a mdbootstrap table, mapping the data array
)
}
export default DriversStandingsComponent;
Run Code Online (Sandbox Code Playgroud)
我真的不明白为什么会发生这种情况,以及它是否会影响服务器性能。
有解决这个问题的想法吗?我什至不知道这本身是否是一个错误
我正在尝试通过 AWS API Gateway 创建一个 API 测试函数,以及一个通过 Axios 的 Vue 应用程序调用的 Lambda 函数。它应该从输入元素发送姓名和电子邮件。每次我收到此错误时:
Access to XMLHttpRequest at '[API Gateway URL]' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
Run Code Online (Sandbox Code Playgroud)
我已在 API 网关设置中的每个步骤/资源上启用了 CORS(根据本文)。下面是 Vue 组件的代码:
<template>
<div data-app>
<div class="cell" id="testForm">
{{responseMsg}}
<label>Name</label>
<input v-model="name" type="text" placeholder="Name">
<label>Email Address</label>
<input v-model="email" type="email" placeholder="Email Address">
<button v-on:click="formFunction">Submit</button>
</div>
</div>
</template>
<script>
import axios …Run Code Online (Sandbox Code Playgroud) 我正在尝试进行反应查询突变(使用 axios,但如果我切换到 fetch API,我会得到相同的行为)。
我是这样设置的。
const mutation = useMutation(
() => {
axios.post("http://swapi.dev/api/foobar", {});
},
{
onSuccess: () => {
console.log("success");
},
onError: () => {
console.log("error");
},
}
);
Run Code Online (Sandbox Code Playgroud)
URL 可以是任何失败的内容。我已经在我正在使用的真实 API 上进行了尝试,返回了 500 和 404 错误。
我按如下方式触发突变。
mutation.mutate();
Run Code Online (Sandbox Code Playgroud)
每次我在控制台中显示“成功”。处理程序onError从不开火。在 Chrome 的网络选项卡中查看时,这些调用会返回预期的错误(并显示控制台错误)。
我正在使用react-query 3.3.6和axios 0.21.1(都是最新的发行版本)。
有人能指出我正确的方向吗?
我正在尝试使用 Axios 发送 post 请求,并且我还想从服务器访问数据。我的代码是
axios({
method: 'post',
url: '/register/',
headers: {'Content-Type' : 'application/json'},
body: JSON.stringify({fname, lname, username, email, pass})
})
.then((res) => {
console.log(res)
})
.catch(err => {
console.log(err)
})
// and my backend code is
const express = require('express')
const router = express.Router()
router.post('/', async (req, res, next) => {
const firstname = ''
})
Run Code Online (Sandbox Code Playgroud)
请求已正确发送,我的服务器也接受该请求。但我不知道如何从我的服务器获取这些值。
请帮我。代码工作正常,只需帮助我获取服务器端代码上的值
我想使用 axios 和 Nestjs 向外部 api 发出请求。
我使用 axios
接受了 Nestjs 这个答案,而不是在控制器中执行请求,而是创建了一个服务
// controller
import { Controller, Get } from '@nestjs/common';
import { CollectService } from './collect.service';
@Controller('collect')
export class CollectController {
constructor(private collectService: CollectService) {}
@Get()
getResponse(){
this.getResponse();
}
}
// ----------service ------------------------
import { Injectable, HttpService } from '@nestjs/common';
@Injectable()
export class CollectService {
constructor(private httpService: HttpService) {}
async getResponse() {
const response = await this.httpService.get('https://reqres.in/api/users/2').toPromise();
return response.data;
}
}
Run Code Online (Sandbox Code Playgroud)
这给了我一个 stackoverflow
[Nest] 23928 - 02/28/2021, 12:16:18 PM …Run Code Online (Sandbox Code Playgroud) 我正在向 URL 端点发出 GET 请求,该端点使用 axios 在 Node/Express 设置上发回 CSV 文件。
如何读取该文件并将其解析为一个数组,其中包含每行数据的对象?我喜欢“neat-csv”如何处理解析的示例,但我愿意接受建议。
const response = await axios.get("url/end/point",{ responseType: 'blob',});
Run Code Online (Sandbox Code Playgroud)
到目前为止,除了请求之外,我没有任何实际的实现示例,因为我对从哪里开始没有明确的看法,并且在网上找不到任何好的指南。我找到的所有指南都涉及请求文件,然后将其保存到我不想要的文件系统中。我只想请求该文件,解析它,然后通过我拥有的 Socket.io 连接广播 CSV 文件中的数据。
Logginresponse.data清楚地给出了数据输出,但当然没有格式化。只是原始数据/文本。
在响应中有一个Content-Disposition参数,内容为attachment; filename=name_of_file.csv
如果有帮助的话?
提前欢呼并致谢!
我是 Nuxt.js/Vue.js 的新手,所以这里有一些新手问题:D
我在从 Nuxt.js 应用程序中的联系人发送邮件时遇到问题。我正在尝试使用 nuxt-mailer 但无法使其工作。我已经安装了axiosnuxt -mail。
我收到 500(内部服务器错误)。
所以我将其添加到nuxt.config.js:
'@nuxtjs/axios',
['nuxt-mail', {
message: {
to: 'my-email',
},
smtp: {
host: "localhost",
port: 587,
},
}],
Run Code Online (Sandbox Code Playgroud)
我是否应该将邮件放在“收件人”中我想要接收邮件的地方?我应该localhost进站host还是http://localhost?最后,我应该用什么双关语来表达“港口”?我的本地主机上的帖子是 3000 吗?
好吧,接下来,我在组件中的表单如下所示:
<template>
<div class="container">
<form>
<label for="name">Ditt namn</label>
<input id="name" type="text" v-model="name"/>
<label for="email">Din epostadress</label>
<input id="email" type="email" v-model="email"/>
<label for="phone">Telefon</label>
<input id="phone" type="phone" v-model="phone"/>
<label for="message"> Meddelande: </label>
<textarea id="message" v-model="message"/>
<button type="submit" @click.prevent="send">Send email </button>
</form> …Run Code Online (Sandbox Code Playgroud) 我有以下代码
const {
isLoading,
error,
data: calculatorProducts
} = useQuery('fetchSomething', ()=> fetchFunc())
Run Code Online (Sandbox Code Playgroud)
当我访问我的主页时应该调用此函数,但是当从另一个页面返回此路由时,不会触发此请求,并且我没有获取新数据。我想要的是每次像 useEffect 一样调用这个查询
我正在开发一个Laravel 8在后端和Nuxtjs前端使用的应用程序。Axios我的问题是,每次我使用任何方法发出请求时,Laravel 都会创建一个新会话。例如,这会阻止我检查 csrf cookie,因为每次都会生成一个新会话。我真的不知道该怎么办,我想得到你的帮助......
获取会话令牌的示例代码:
Route::get('/test', function() {
return request()->session()->token();
});
Run Code Online (Sandbox Code Playgroud)
第一次尝试:IM23wUv9NTY2IUu9gAJix6TTg3IFjjgOkasOkRhn
第二次尝试:bMpuaa9Ink4dOUUJNEyJnbYYKSqSACP216Xq08Uh
因此,我的每个请求总是得到 419。
代码:
const self = this
const rootURL = self.$axios.defaults.baseURL.replace('/api', '')
self.$axios.get('/sanctum/csrf-cookie', {
baseURL: rootURL
}).then(() => {
self.$axios.post('/auth/login', {
email: self.email,
password: self.password,
}, {withCredentials: true}).then(({data: response}) => {
console.log(response)
})
})
Run Code Online (Sandbox Code Playgroud)
回复:
{
"message": "CSRF token mismatch.",
"exception": "Symfony\\Component\\HttpKernel\\Exception\\HttpException",
"file": "/home/sidik/Projets/Colisone/web/laravel-backend/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php",
"line": 387,
"trace": [
{
"file": "/home/sidik/Projets/Colisone/web/laravel-backend/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php",
"line": 332,
"function": "prepareException",
"class": "Illuminate\\Foundation\\Exceptions\\Handler",
"type": "->"
}, …Run Code Online (Sandbox Code Playgroud) 我从nestJS文档(https://docs.nestjs.com/techniques/http-module#http-module)中获取了这个示例,这是我的问题的一个最小示例:
@Injectable()
export class CatsService {
constructor(private httpService: HttpService) {}
findAll(): Observable<AxiosResponse<Cat[]>> {
return this.httpService.get('http://localhost:3000/cats');
}
}
Run Code Online (Sandbox Code Playgroud)
如何从 Observable<AxiosResponse<Cat[]>> 中提取实际的猫数组?我尝试了以下操作,但它给了我一个订阅者对象,我也不知道如何解开该对象以获取实际数据。
const cats = await this.catsService.findAll().subscribe((val) => val);
Run Code Online (Sandbox Code Playgroud) axios ×10
javascript ×4
reactjs ×3
nestjs ×2
node.js ×2
nuxt.js ×2
react-query ×2
typescript ×2
vue.js ×2
ajax ×1
api ×1
aws-lambda ×1
csv ×1
email ×1
express ×1
laravel ×1
php ×1
react-native ×1
request ×1