vue axios同步请求解决方案

在vue项目里面,需要循环发送ajax请求,出现的问题就是循环结束,第一次服务器还没返回,导致数据处理错误,需要使用同步请求

解决方

目前没有发现axios可以同步请求,所以只能使用jQuery,配置同步请求;

rush:js;"> $.ajax({ url:'/comm/test1.PHP',type:'POST',//GET async:false,//或false,是否异步 data:{ name:'yang',age:25 },timeout:5000,//超时时间 dataType:'json',//返回的数据格式: beforeSend:function(xhr){ },success:function(data,textStatus,jqXHR){ },error:function(xhr,textStatus){ },complete:function(){ } })

vue 安装jQuery插件

rush:js;"> $ npm install jquery --save

打开 build/webpack.base.conf 配置文件

imsun; white-space: normal; word-spacing: 0px; text-transform: none; font-weight: normal; color: rgb(0,0); font-style: normal; text-align: center; orphans: 2; widows: 2; letter-spacing: normal; text-indent: 0px; font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px">

这里写图片描述

imsun; white-space: normal; word-spacing: 0px; text-transform: none; font-weight: normal; color: rgb(0,0); font-style: normal; text-align: center; orphans: 2; widows: 2; letter-spacing: normal; text-indent: 0px; font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px">

这里写图片描述

配置完成后,在需要组件使用import $ from 'jquery';

就可以使用!

总结

以上所述是小编给大家介绍的vue axios同步请求解决方案。编程之家 jb51.cc 收集整理的教程希望能对你有所帮助,如果觉得编程之家不错,可分享给好友!感谢支持

相关文章

可以通过min-width属性来设置el-table-column的最小宽度。以...
yarn dev,当文件变动后,会自动重启。 yanr start不会自动重...
ref 用于创建一个对值的响应式引用。这个值可以是原始值(如...
通过修改 getWK005 函数来实现这一点。这里的 query 参数就是...
<el-form-item label="入库类型" ...
API 变动 样式类名变化: 一些组件的样式类名有所变动,可能需...