当前位置: ManBetXapp > 百科 > 科技 >正文

vue async

人气:312 ℃ /2023-01-11 17:18:34

vue async是什么呢?下面就让我们一起来了解一下吧:

async一般来说是一个加在函数前的修饰符,被async定义的函数通常会默认返回一个Promise对象resolve的值。因此对async函数是能够直接进行then的,其返回值也就是通过then方法传入的函数。

说明:

在ES7标准中其实就已经新增了async和await关键字,来作为处理异步请求的一种解决方案,实际上也就是一个语法糖,尽管在ES6中就已经能够运用生成器语法完成同样的操作,但是async/await的出现在使用这样的方式处理异步请求会更加简单明了。

参考范例:

1、使用async/await语法,示例代码如下:

function resolveAfter2Seconds() {

return new Promise(resolve => {

setTimeout(() => {

resolve('resolved');

}, 2000);

});

}

async function asyncCall() {

console.log('calling');

var result = await resolveAfter2Seconds();

console.log(result);

// expected output: 'resolved'

}

asyncCall();

以上就是小编的分享了,希望能够帮助到大家。

vue async await

搜索更多有关“ vue async”的信息 [百度搜索] [SoGou搜索] [头条搜索] [360搜索]
CopyRight © 2008-2024 ManBetXappAll Rights Reserved. 手机版