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

为什么建设营销型网站学习html5的网站

为什么建设营销型网站,学习html5的网站,成都装修公司十大排名,oa系统网站建设背景 背景就是遇到了一个比较烦人的模块#xff0c;里面的涉及到了大量的async 和 awiat。发现大多人对这个语法糖一知半解#xff0c;然后大量的滥用#xff0c;整理一下 async 前置知识#xff1a; 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 worldii因为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 worldasync 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 worldawait 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 // hello1async 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() // 出错了 hello3、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() // 出错了 hellofunction 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(); // 出错了 // helloasync function ll() {let w await Promise.reject(出错了);console.log(w);let y await Promise.reject(hello);console.log(y); } ll(); // Promise {rejected: 出错了}
http://www.hkea.cn/news/14357579/

相关文章:

  • 甘肃省建设厅官网站深圳建网建网站
  • 凡客网站设计网站二次备案
  • 设计友好的网站服务一流的做网站
  • 传媒网站模板seo网站推广目的
  • 网站建设优化推广排名免费域名创建入口在哪
  • uiapp博客 个人网站天津 网站设计制作公司
  • 天猫入驻网站建设深圳创业补贴政策2021申请流程
  • 徐州html5响应式网站建设哔哩哔哩免费网站观看
  • 最专业的网站建设seo优化服务公司创建wordpress博客
  • 网站标题正确书写标准天猫网站建设可行性分析
  • 河北建设厅查询网站郴州58网站
  • php网站源码安装教程做旅游门票网站需要什么材料
  • 手机网站用什么域名深圳开发app的公司有哪些
  • 智能建站系统哪个好建设银行嘉兴分行网站首页
  • 网页自助建站wordpress 建站 域名
  • 网站的首页面设计网址安全检测
  • 电商网站开发公司杭州企业如何建设网站
  • 可以找酒店案例的网站网站收录了怎么做排名
  • 建设美食网站的作用用vs2010做的网站的源码
  • 北京专业网站翻译影音字幕翻译速记速记速记快而高效iis网站连接数
  • 运动品牌网站开发题目来源软件平台搭建流程
  • 无锡网站制作优化推广公司营销网站建设维护
  • 集团网站源码wordpress主题 下单
  • 将自己做的网站发布到网上高端品牌手机
  • ssh做电商 网站登陆页面模板
  • 怎么申请一个商城网站.广州网站到首页排名
  • ppt做书模板下载网站58黄页
  • 哈尔滨网站制作招聘百度收录网站入口
  • 个人网站的基本风格怎么做英文版的网站
  • 百度怎么做网站域名电商网站开发技术