-
Js performs asynchronous operations in a loop and then adds each asynchronous result to an array. How can this array be used outside the loop?
How does the code return only the result after the last asynchronous operation in the for loop is completed as shown in the figure? Please stop by and give me a hand.
...
-
Mini Program's request failed due to the difference between the encapsulated promise and the direct request parameters.
this is encapsulated
function request(url, params) {
let promise = new Promise(function (resolve, reject) {
wx.request({
url: url,
data: params,
header: {
X-Token-With : token
...
-
If promise.all has two p objects, can't the parameters passed to the callback function be divided into two results?
for example
Promis.all([p1,p2]).then((p1result,p2result)=>{});
if p1 returns [1mem2p3] p2 returns [4mage5magin6] the final result is a parameter [1mem2magin3], what should I do if I want to use the results of two p objects respectively?
...
-
The problem with promise
as soon as I came into contact with promise, I wrote a demo by myself. Ask .
Why my then only executes once, and how to make it execute multiple times
var test = 0;
var promise = new Promise(resolve => {
$( .btn ).on( click ,()=...
-
In nodejs, stats is used to judge whether the file is a folder, and the resolve () statement of promise is placed in the block of judgment statement, which leads to the error of the program.
recently in learning the koa framework to build a node environment, writing a small case requires the following: the node program reads a path, and if it is a folder, put the folder name into the list collection. Promise is used in the program to do asy...
-
The question about promise
a () {
return new Promise((res, rej) => {
:
getData().then(res => {
this.data = res.data.reslut
console.log(this.data)
})
});
}
the a method is defined in vue , and the a method is ca...
-
What is the return value of Promise's excutor?
when reading Promise :
var promise1 = new Promise(function(resolve, reject) {
setTimeout(resolve, 100, foo );
});
if an error is thrown in the executor function, the promise state is rejected. The return value of the executor function is ignored...
-
Axios async request. Then () and then. How to write then ()
doctorComments(this.$route.params.hid, this.$route.params.fid, this.doctorHisId, this.createdon, this.pageno, 5) 1.axios
.then(d => { 2.
let dc = new Array()
for(let i=0;i<d.list.length;iPP){
dc[i] = {doctorComments:d.list[i],isZhanshiC...
-
Js chain call problem
write a chained call as follows:
new Man( lan ).sleep(3).eat( apple ).sleep(3).eat( banana );
output: hello, lan--> (pause 3s)-> lan eat apple-> (pause 3s)-> lan eat banana my code is as follows:
class Man {
constructor(name) {
th...
-
Promise has conditional judgment in then and returns different Promise objects. How can you determine which condition it comes from in the next then?
let p1 = ()=>{
data = xxxx xxx true false
return new Promise((res,rej)=>{
res(data)
})
}
p2 p3 promise
let p2 = ....
let p3 = ....
p1()
.then(
(data)=>{
if (data) {
return p2
} ...
-
How does Promise + exports output values directly instead of promise objects?
a.js
a.js
module.exports = {
list: async () => {
return await axios.get(getIntelligentPlatform)
},
}
b.js
b.js
const { list } = require( .. models meibrain )
list().then(res => {
console.log(res.data.obj)
})
...
-
How does WeChat Mini Programs promise get the returned value and pass it into the variable, which is the data of res?
util.getToken (). Then (token = > {
return util.wxRequest({
url: ports.orderList,
method: POST ,
data: { user_id: 32793, ofstatus:10},
header: { X-Auth-Token : token, content-type ...
-
How to understand the safeThen function in Promise source code?
Source code see here
Promise.prototype.then = function(onFulfilled, onRejected) {
if (this.constructor !== Promise) {
return safeThen(this, onFulfilled, onRejected);
}
var res = new Promise(noop);
handle(this, new Handler(onFulfilled, onR...
-
Various implementations of promise maintain an array _ deferreds that holds the callback function set registered by the then method. When will this array reach 2 items?
I have reviewed articles of various promise implementations, all of which indicate that it is necessary to maintain a _ deferreds to save the callback function set information registered by the then method, and some implementations maintain onResolve...
-
Call the backend API in batch to add objects, but check whether there are duplicate values one by one before adding them. How to write promise?
vue.js environment, you need to fill in multiple objects on the page and add them to the backend in batches. Currently, there are two APIs in api.js: apiCheckDuplicated (name) apiCreateNew (name) ajax calls implemented by axios.
now the page has en...
-
How to control the execution order by calling promise in forEach
recently, I am doing a web crawler, first grab the list page, then get the url, of all the content pages of the list page, and then call the url loop of all the list pages to the crawling method, which leads to the uncontrollable crawling order. I want ...
-
Deployment server access after the vue project is packaged promise error is not defined in the lower version browser
The project uses axios, packaging to open Index.html as a local file and does not report errors in a lower version browser, but once deployed to the server, it will report errors that are not defined by promise.
tried to introduce the babel-polyfill ...
-
About the problem of asynchronous login in WeChat Mini Programs? The problem of File execution order and promise problem
at present, I have written the login operation in app.js. After obtaining Wechat s code, I obtain the authentication access-token from my own server. the code is as follows
app.js
onLaunch: function () {
wx.login({
success: ...
-
How Promise does not return the promise object, but directly returns the value of resolve
functiong getPromise(){
return Promise.resolve( something );
}
let getSomething = async function(){
let a = await getPromise();
return a;
}
The async function returns a promise object, so there is no way to return a non-promise ob...
-
What's the difference between using reject and return reject in Promise's internal functions
can be run in Chrome. The program details are shown below:
will the current task queue be rolled back to the status of the Project sibling as soon as you execute reject,?
...