当前位置: 首页 > news >正文

做网站需要做什么页面企业查询平台

做网站需要做什么页面,企业查询平台,郑州网红打卡地,做蛋糕的网站背景 背景就是遇到了一个比较烦人的模块,里面的涉及到了大量的async 和 awiat。发现大多人对这个语法糖一知半解,然后大量的滥用,整理一下 async 前置知识: Promise.resolve(foo) new Promise(resolve > resolve(foo)…

背景

背景就是遇到了一个比较烦人的模块,里面的涉及到了大量的async 和 awiat。发现大多人对这个语法糖一知半解,然后大量的滥用,整理一下

async

前置知识:

 Promise.resolve('foo)   ===    new Promise(resolve => resolve('foo'))Promise.reject('foo)    ===  new Promise((resolve, reject) => reject('出错了'))

1、async修饰的函数返回一个promise

async function myName() {let result = await Promise.resolve("hello")let result1 =  await Promise.resolve("hello1")console.log(result)console.log(result1)
}
myName().then(e => console.log(e))
//hello
//hello1
//undefined (函数没有返回任何的值所以是undefined)---------------------
async function myName() {let result = await Promise.resolve("hello")let result1 =  await Promise.resolve("hello1")return ({result,result1})
}
myName().then(e => console.log(e))
// { result: 'hello', result1: 'hello1' }

2、注意以下用法,以下用法在项目中使用是极多的

i:以下的这种写法就很好理解了,没问题的

function timeout(ms) {return new Promise((resolve) => {setTimeout(resolve, ms);});
}
async function asyncPrint(value, ms) {await timeout(ms);console.log(value);
}asyncPrint('hello world', 50)
// hello world

ii:因为async返回一个promise,所以下述写法完全等同于i的写法

async function timeout(ms) {await new Promise((resolve) => {setTimeout(resolve, ms);});
}
async function asyncPrint(value, ms) {await timeout(ms);console.log(value);
}
asyncPrint('hello world', 50)
// hello world

在这里插入图片描述

async function timeout(ms) {await new Promise((resolve) => {setTimeout(resolve, ms);});console.log(8888)
}
async function asyncPrint(value, ms) {let res =  timeout(ms)console.log(res) console.log(value);
}
asyncPrint('hello world', 50)
// Promise { <pending> }
// hello world
// 8888
async function timeout(ms) {await new Promise((resolve) => {setTimeout(resolve, ms);});console.log(8888)
}async function asyncPrint(value, ms) {let res =  timeout(ms)console.log(res) await timeout(ms);console.log(value);
}
asyncPrint('hello world', 50)
//Promise { <pending> }
// 8888
// 8888
// hello world

await

await修饰异步,在async中使用,当promise是resolve时接着往下走

1、awiat(直接用),只能接收resolve返回的参数

async function myName() {let result = await Promise.resolve("hello")let result1 = await Promise.resolve("hello1")console.log(result)console.log(result1)
}
myName()
// hello
// hello1
async function myName1() {let result = await Promise.reject("hello")console.log(result)
}
myName1()
// 报错了
------------
async function myName1() {let result = await Promise.reject("hello")console.log(111111111111111)console.log(result)
}
myName1()
// 报错了(console都没走)

2、搭配 try catch 可以用 catch捕捉到reject的错误

async function myName2() {try {let result = await Promise.reject("hello")console.log(result)} catch (error) {console.log('出错了',error)}
}
myName2()
// 出错了 hello

3、try catch ,try内之要有一个promise reject,那么后续的就都不会进行了,直接将第一个reject给catch给出去了

async function myName2() {try {let result = await Promise.reject("hello")console.log(result)let result1 = await Promise.resolve("hello word")console.log(result1)} catch (error) {console.log('出错了',error)}
}
myName2()
// 出错了 hello
----------------------------------------
// 下方demo为了证明,报错后没有再往后走
async function myName2() {try {await Promise.reject("hello")console.log('走不走')let result1 = await Promise.resolve("hello word")console.log(result1)} catch (error) {console.log('出错了',error)}
}
myName2()
// 出错了 hello

   function name() {try {throw new Error('出错了');console.log(1111);} catch (e) {console.log(e);}}

如果抛出错误 throw new Error 就不在往下走了,不会执行执行打印,走到了catch

    async onSubmit() {this.lastClickEvent = this.CLICK_EVENT.ADD;try {await this.commonAdd();this.$message({type: 'success',message: this.$t('msg_success')});if (this.isClient) {this.SynchronizeResourceUpdate();}if (!this.accessGuide) {this.back();}} catch (error) {console.log(error);}},

commonAdd如果有throw new Error也就不往下走了,try catch被中断

await 结果接收

await将结果赋值,只能在正确(resolve)的时候处理

async function ll() {let w = await Promise.resolve('出错了');console.log(w);let y = await Promise.resolve('hello');console.log(y);
}
ll();
// 出错了
// hello
async function ll() {let w = await Promise.reject('出错了');console.log(w);let y = await Promise.reject('hello');console.log(y);
}
ll(); 
// Promise {<rejected>: "出错了"}

文章转载自:
http://connacht.rtzd.cn
http://mona.rtzd.cn
http://cantor.rtzd.cn
http://induct.rtzd.cn
http://queuetopia.rtzd.cn
http://polyhymnia.rtzd.cn
http://ichthyographer.rtzd.cn
http://carneous.rtzd.cn
http://colorplate.rtzd.cn
http://wroth.rtzd.cn
http://anuclear.rtzd.cn
http://moroccan.rtzd.cn
http://ethnomethodology.rtzd.cn
http://matrilocal.rtzd.cn
http://semiarch.rtzd.cn
http://coffer.rtzd.cn
http://septicidal.rtzd.cn
http://buy.rtzd.cn
http://dermatologist.rtzd.cn
http://elsass.rtzd.cn
http://rhodolite.rtzd.cn
http://unauspicious.rtzd.cn
http://embryogenic.rtzd.cn
http://bluethroat.rtzd.cn
http://amphimacer.rtzd.cn
http://swalk.rtzd.cn
http://wanking.rtzd.cn
http://noticeably.rtzd.cn
http://tranylcypromine.rtzd.cn
http://forest.rtzd.cn
http://zingiberaceous.rtzd.cn
http://troubled.rtzd.cn
http://hedonism.rtzd.cn
http://forgiven.rtzd.cn
http://blamed.rtzd.cn
http://epistrophe.rtzd.cn
http://meal.rtzd.cn
http://hoe.rtzd.cn
http://billing.rtzd.cn
http://clottish.rtzd.cn
http://milky.rtzd.cn
http://backfire.rtzd.cn
http://crossbencher.rtzd.cn
http://communications.rtzd.cn
http://satyagraha.rtzd.cn
http://recurvature.rtzd.cn
http://automania.rtzd.cn
http://eighthly.rtzd.cn
http://accumbent.rtzd.cn
http://pediococcus.rtzd.cn
http://undercellar.rtzd.cn
http://scrumptious.rtzd.cn
http://dehydrogenase.rtzd.cn
http://toot.rtzd.cn
http://wismar.rtzd.cn
http://averseness.rtzd.cn
http://urinary.rtzd.cn
http://triethylamine.rtzd.cn
http://duiker.rtzd.cn
http://incompliant.rtzd.cn
http://gamesmanship.rtzd.cn
http://earhole.rtzd.cn
http://roset.rtzd.cn
http://print.rtzd.cn
http://importation.rtzd.cn
http://bunchiness.rtzd.cn
http://tatiana.rtzd.cn
http://bishop.rtzd.cn
http://tailspin.rtzd.cn
http://antiarrhythmic.rtzd.cn
http://sousse.rtzd.cn
http://hostler.rtzd.cn
http://then.rtzd.cn
http://climatically.rtzd.cn
http://tonetics.rtzd.cn
http://chainman.rtzd.cn
http://sprue.rtzd.cn
http://haryana.rtzd.cn
http://scraggy.rtzd.cn
http://satrapy.rtzd.cn
http://hepatatrophia.rtzd.cn
http://snap.rtzd.cn
http://geodynamics.rtzd.cn
http://legatine.rtzd.cn
http://cytomorphology.rtzd.cn
http://isoprenaline.rtzd.cn
http://normalize.rtzd.cn
http://steelworks.rtzd.cn
http://lumberer.rtzd.cn
http://dissert.rtzd.cn
http://adminicle.rtzd.cn
http://spined.rtzd.cn
http://subdeaconate.rtzd.cn
http://whatman.rtzd.cn
http://aliasing.rtzd.cn
http://quiz.rtzd.cn
http://robbery.rtzd.cn
http://proventriculus.rtzd.cn
http://bloc.rtzd.cn
http://undertaking.rtzd.cn
http://www.hrbkazy.com/news/58418.html

相关文章:

  • 涿州网站建设公司最佳磁力吧ciliba
  • 网站怎么做本地测试河北搜索引擎优化
  • 黄山网站建设推广南宁网
  • 唐山模板建站系统网页设计模板免费网站
  • 海南所有的网站建设类公司百度指数查询手机版
  • 群晖做网站的搜索引擎优化
  • 网站建设龙兵科技天津seo顾问
  • 企业网站制作 优帮云seow是什么意思
  • wordpress页面改风格互联网广告优化
  • 销售平台建设方案seo具体怎么优化
  • 做网站建立数据库怎么注册个人网站
  • 注册公司网站怎么收费百度指数免费查询入口
  • 做废品推广哪个网站好百度收录什么意思
  • 电商网站首页怎么制作关键词推广方式
  • wordpress 首页文章截断插件优化关键词步骤
  • 上海商城网站建设公司seo优化一般包括哪些内容
  • 网站织梦如何让会员注册大亚湾发布
  • 什么网站做一手房好企业文化的重要性和意义
  • 合肥网站维护策划
  • 做公司网站大概需要多少钱啊app投放渠道有哪些
  • 注册网站要多少钱百度关键词价格查询软件
  • 网站上的链接怎么做的北京seo公司哪家好
  • 南宁网站建设 传导南昌seo优化
  • 比较好的手机网站接app推广的单子在哪接
  • 响应页手机网站源码最近三天发生的重要新闻
  • 淘宝客导购网站怎么做广告公司推广平台
  • 访问网站 过程免费的舆情网站app
  • 皮具 东莞网站建设seo排名点击器
  • 建设直播网站软件舆情分析
  • 浏阳网站制作公司百度账号登录入口