草庐IT

index-async

全部标签

javascript - Async/Await 无法按预期使用 Promise.all 和 .map 函数

我有很多正在使用的async函数,但我遇到了一个奇怪的问题。我的代码,工作,看起来像:asyncmainAsyncFunc(metadata){letfiles=metadata.map(data=>this.anotherAsyncFunc(data.url));returnPromise.all(files);}anotherAsyncFunc函数如下所示:asyncanotherAsyncFunc(url){returnawaitaxios({url,}).then(res=>res.data).catch(err=>{throwerr;});}当我尝试将更多数据附加到第一个函数

javascript - 使用 await/async 从 axios 获取响应

我正在尝试从axios获取JSON对象'usestrict'asyncfunctiongetData(){try{varip=location.host;awaitaxios({url:http()+ip+'/getData',method:'POST',timeout:8000,headers:{'Content-Type':'application/json',}}).then(function(res){console.dir(res);//wearegoodhere,thereshastheJSONdatareturnres;}).catch(function(err){con

javascript - highcharts 工具提示 z-index

我正在尝试让highcharts工具提示有一个zIndex使用useHTML将其定位在另一个HTML元素上。请参阅此fiddle:http://jsfiddle.net/sDu8V/我希望工具提示越过粉红色方框,而不是下方。我错过了什么? 最佳答案 可能的解决方案:http://jsfiddle.net/sDu8V/1/所需的CSS:.highcharts-container{position:inherit!important;}.highcharts-tooltip{z-index:9998;}感谢@Piotr,更新了4.1.x

javascript - Magento 中的 HTML <script> async 属性

我想尝试在Magento1.9.1的PrototypeJavaScriptscript标签中插入“async”属性:我会得到这样的结果:我必须在哪里插入“async”?带有此行代码的文件是什么?谢谢 最佳答案 看文件app/design/frontend///layout/page.xml(或将app/design/frontend/base/default/layout/page.xml复制到您的主题中)。在此文件中,搜索以下行:prototype/prototype.js并更改addJs电话:prototype/prototyp

javascript - 几乎所有地方都可以使用 async/await 吗?

我目前正在编写供个人使用的小型NodeJSCLI工具,我决定尝试使用Babel的ES7async/await功能。它是一个网络工具,所以我显然有异步网络请求。我为request包写了一个简单的包装器:exportdefaultfunction(options){returnnewPromise(function(resolve,reject){request({...options,followAllRedirects:true,headers:{"user-agent":"Mozilla/5.0(WindowsNT10.0;WOW64;rv:47.0)Gecko/20100101Fi

javascript - 通过 gulp 从 index.html 中删除脚本

我在我们的应用程序中使用gulp,我们在Gulpfile.js中有2个流程,一个用于生产,第二个用于开发,但我不想保留2个index.html文件,例如index.html和index.dev。html,我想要一个index.html文件,但是对于生产构建,我有一些不需要的脚本,例如.问题是:如何通过Gulp从html中删除某些内容? 最佳答案 您可以使用专用于此特定目的的gulp-html-replace插件:https://www.npmjs.org/package/gulp-html-replace

Javascript Async=true 属性

我在某个未具名vendor的文档中看到此代码示例。它似乎异步加载脚本,然后从中调用函数。我意识到if-undefined检查可以防止明显的错误,但这不是完全不正确吗?我相信在IE8/9中它会正常工作,但会阻塞执行,直到加载并执行LOADER_URL脚本;而且我相信许多其他支持异步属性的浏览器,这只会导致内联block仅在部分时间执行ifblock内的代码。文档指出“标签是异步的,不会减慢页面的加载速度。”if(typeof(OBJECT_DEFINED_IN_LOADER_URL)!="undefined"){OBJECT_DEFINED_IN_LOADER_URL.Load(fals

javascript - 如何使用 async/await 将此回调转换为 promise?

以下函数从url获取图像,加载它,并返回它的宽度和高度:functiongetImageData(url){constimg=newImage()img.addEventListener('load',function(){return{width:this.naturalWidth,height:this.naturalHeight}})img.src=url}问题是,如果我这样做:ready(){console.log(getImageData(this.url))}我得到undefined因为函数运行但图像尚未加载。如何使用await/async只在图片加载完成且宽高已经可用时才

javascript - 模块构建失败(来自 ./node_modules/babel-loader/lib/index.js): Error: Cannot find module 'babel-preset-react'

在尝试使用Webpack4和Babel7构建React应用程序时,我遇到了以下错误。ERRORin./src/index.jsModulebuildfailed(from./node_modules/babel-loader/lib/index.js):Error:Cannotfindmodule'babel-preset-react'from'/Users/me/Desktop/reflask'-Ifyouwanttoresolve"react",use"module:react"-Didyoumean"@babel/react"?atFunction.module.exports[

javascript - AngularJS ngMessages 无法绑定(bind)到 $index 表达式

我正在构建一个Angular表单,它需要ngRepeat中的可重复表单元素。Thisisrequired{{form|json:4}}Angular现在支持动态声明的input名称,因此您不必执行以下操作:并且您可以在ngRepeat中使用{{$index}}来动态声明项。但这似乎不适用于ngMessages,当我尝试将索引绑定(bind)到其中时会抛出错误。即这个:抛出这个:Error:[$parse:syntax]SyntaxError:Token'{'isanunexpectedtokenatcolumn16oftheexpression[form.something_{{$in