axios

Vue.js this is undefined inside computed property

大憨熊 提交于 2020-08-03 06:02:13
问题 I have following input tag with model selectedProp : <input type="text" v-model="selectedProp" /> and I want to iterate through items like this: <div v-for="item of filteredItems">{{item.prop}}</div> Here's the script for the component: export default { name: 'App', data() { return { items: [], selectedProp: "", projects: [], errors: [] } }, created() { axios.get(`${URL}`) .then(response => { // JSON responses are automatically parsed. this.items = response.data; }) .catch(e => { this.errors

How to post multiple Axios requests at the same time?

你。 提交于 2020-08-02 08:21:01
问题 At this moment I have a webpage in which a long list of Axios POST calls are being made. Now, the requests seem to be sent in parallel (JavaScript continues sending the next request before the result is received). However, the results seem to be returned one by one, not simultaneously. Let's say one POST call to the PHP script takes 4 seconds and I need to make 10 calls. It would currently take 4 seconds per call, which would be 40 seconds in total. I hope to find a solution to both and

How to post multiple Axios requests at the same time?

让人想犯罪 __ 提交于 2020-08-02 08:19:23
问题 At this moment I have a webpage in which a long list of Axios POST calls are being made. Now, the requests seem to be sent in parallel (JavaScript continues sending the next request before the result is received). However, the results seem to be returned one by one, not simultaneously. Let's say one POST call to the PHP script takes 4 seconds and I need to make 10 calls. It would currently take 4 seconds per call, which would be 40 seconds in total. I hope to find a solution to both and

Canceling an Axios REST call in React Hooks useEffects cleanup failing

谁都会走 提交于 2020-08-02 07:34:18
问题 I'm obviously not cleaning up correctly and cancelling the axios GET request the way I should be. On my local, I get a warning that says Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function. On stackblitz, my code works, but for some reason I can't click the button to show the error. It just always shows the returned data. https:

Canceling an Axios REST call in React Hooks useEffects cleanup failing

烂漫一生 提交于 2020-08-02 07:34:17
问题 I'm obviously not cleaning up correctly and cancelling the axios GET request the way I should be. On my local, I get a warning that says Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function. On stackblitz, my code works, but for some reason I can't click the button to show the error. It just always shows the returned data. https:

How to enable POST method on heroku server (for React app)? I am getting 405 method not allowed

房东的猫 提交于 2020-07-31 04:37:25
问题 I am getting 405 method not allowed. I am using axios.post for login. The form is taking input username and password and post to get authenticate. But POST method not allowed at heroku error in console. Please help me to let me know how to enable POST method on heroku. or any solution. Thanks in advanceenter image description here 回答1: This is an axios post example: axios.post("test/test", {userName:'..', password:'..'}).then((result) => onSuccess(result.data), (error) => onError(error)); If

Vue 使用typescript, 优雅的调用swagger API

荒凉一梦 提交于 2020-07-29 11:11:50
Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务,后端集成下Swagger,然后就可以提供一个在线文档地址给前端同学。 前端如何优雅的调用呢? 入门版 根据文档,用axios自动来调用 // 应用管理相关接口 import axios from '../interceptors.js' // 获取应用列表 export const getList = (data) => { return axios({ url: '/app/list?sort=createdDate,desc', method: 'get', params: data }) } 这里的问题是,有多少个接口,你就要编写多少个函数,且数据结构需要查看文档获取。 进阶版本 使用typescript,编写API,通过Type定义数据结构,进行约束。 问题: 还是需要手写 优雅版本 swagger 其实是一个json-schema描述文档,我们可以基于此,自动生成。 很早之前,写过一个插件 generator-swagger-2-t , 简单的实现了将swagger生成typescript api。 今天,笔者对这个做了升级,方便支持后端返回的泛型数据结构。 安装 需要同时安装 Yeoman 和 -swagger-2-ts npm install -g

C# 超大文件上传和断点续传的实现

瘦欲@ 提交于 2020-07-29 10:56:12
以ASP.NET Core WebAPI 作后端 API ,用 Vue 构建前端页面,用 Axios 从前端访问后端 API ,包括文件的上传和下载。 准备文件上传的API #region 文件上传 可以带参数 [HttpPost("upload")] public JsonResult uploadProject(IFormFile file, string userId) { if (file != null) { var fileDir = "D:\\aaa"; if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } //文件名称 string projectFileName = file.FileName; //上传的文件的路径 string filePath = fileDir + $@"\{projectFileName}"; using (FileStream fs = System.IO.File.Create(filePath)) { file.CopyTo(fs); fs.Flush(); } return Json("ok"); }else{ return Json("no"); } } #endregion 前端vue上传组件 ( 利用Form表单上传 )

axios 用 params/data 发送参数给 springboot controller,如何才能正确获取

蓝咒 提交于 2020-07-29 06:13:28
今天有人遇到接口调用不通的情况,粗略看了一下是axios跨域请求引起了。找到问题,处理就简单多了。 但是我看其代码,发现比较有意思 export function agentlist(query) { return request({ url: /agent/list' , method: 'get' , params: query }) } export function editagent(data) { return request({ url: '/agent/editagent' , method: 'post' , data:data }) } export function deleteagent(id) { return request({ url: '/agent/ delete ' , method: 'post' , params:{id} }) } 上面的代码中的request是axios实例,同是post却出现了data或params做数载体的情况。凭直觉该代码会在后续请求中出现问题,果不其然后续出现各种问题。 出现的问题主要是:前端传递参数给了springboot程序,但是程序中却接收不到数据或只接收到部分数据。出现问题前后端代码如下: 前端: export function login(account, password, orgType) {

js同步异步是什么,常见的同步异步问题及解决方案,简单易懂适合刚入门的小白。

℡╲_俬逩灬. 提交于 2020-07-28 22:27:43
何为异步,何为同步,一篇简短的文章让你看懂; 异步: 异步最经典的就是http请求,比如ajax,axios,setTimeout等,异步就是程序在处理中还没处理完时,不会影响后面的程序执行,你可以理解把异步操作放在一个盒子里,他处理完了拿到结果自己从盒子里出来。 常见问题: 我们需要这个异步操作处理完了才执行下面的操作怎么办,放在以前我们会怎么做,这个函数处理完了,在调取另一个函数,有的索性直接不封装函数,一个方法吧逻辑全部写完,这样看起来代码冗余不说,函数调用的时候灵活性太低,有些函数我们一个页面用四次,那你把这段逻辑复制四次吗,当然不是,我们都是函数封装一次,直接调用四次,那么问题来了,函数一调用完,我们要根据返回的参数调取函数二,函数二调用完要根据返回值调取函数三,如果我们层层嵌套,这样太深了也会导致代码看起来不简洁不明了,有了es6的promise,我们就可以调取他的回调方法.then()或者.catch()方法来进行处理后面的函数调用了,不懂得可以去我主页看promise详解的文章 同步: 同步就是处理的时候我后面程序就不能执行,必须等我处理完在执行后面的程序 常见问题: 同步常见问题就是有时候我们一段代码可能要执行好几秒,那这样就会照成程序卡顿,这样怎么办,简单,吧同步变成异步即可,es6新出的promise完美解决这个问题