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
- 02-18美食
海带怎么切
- 05-15生活
夏天空调温度30合适吗
- 11-24生活
姜黄饮料有哪些
- 03-05教育
中小学生消防安全公开课观后感心得体会范文精选
- 07-11生活
奶酪棒保质期多久
- 08-16游戏
吃鸡昼夜模式怎么进
- 02-20教育
学雷锋月活动总结范文
- 07-23生活
工业是国民经济的什么
推荐
- 1避暑的好地方有哪些473
- 2华为hcip如何报考426
- 3无花果寓意435
- 4教育的本质134
- 5弹拨乐器有哪几种150
- 6写给台湾小朋友的一封信作文143