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

如何才能做好网络营销百度关键词优化大师

如何才能做好网络营销,百度关键词优化大师,开发公司审计稽查的内容,化学产品在哪个网站做推广最好async和await两种语法结合可以让异步代码像同步代码一样。 一、async函数 async函数的返回值为Promise对象promise对象的结果由async函数执行的返回值决定 async function fn() {// 返回一个字符串return 字符串;// 返回的结果不是一个Promise类型的对象&#xf…

async和await两种语法结合可以让异步代码像同步代码一样。

一、async函数

  • async函数的返回值为Promise对象
  • promise对象的结果由async函数执行的返回值决定
async function fn() {// 返回一个字符串return '字符串'// 返回的结果不是一个Promise类型的对象,返回的结果就是成功的Promise对象。return;// 抛出错误,返回的结果是一个失败的Promisethrow new Error('出错啦!');// 返回的结果如果是一个Promise对象return new Promise((resolve,reject)=>{// resolve('成功的数据');reject('失败的数据')});
}const result = fn();
console.log(result);// 调用then方法
result.then(value => {console.log(value);
}, reason => {console.warn(reason);
})

二、await

  • await必须写在async函数中
  • await右侧的表达式一般为Promise对象
  • await返回的是Promise成功的值
  • await的Promise失败了,就会抛出异常,需要通过try…catch捕获处理
// 创建promise对象
const p = new Promise((resolve, reject) => {// resolve("用户数据");reject("失败!!");
})
// await要放在async函数中
async function main() {try {let result = await p;console.log(result);} catch (error) {console.log(error);}
}main();

三、async和await结合

// 1.引入js模块
const fs = require('fs');// 读取“.md”文件
function weixue() {return new Promise((resolve, reject) => {fs.readFile('./resourse/为学.md', (err, data) => {// 如果失败if (err) reject(err);// 如果成功resolve(data);});});
}function yougan() {return new Promise((resolve, reject) => {fs.readFile('./resourse/有感.md', (err, data) => {// 如果失败if (err) reject(err);// 如果成功resolve(data);});});
}
function guankan() {return new Promise((resolve, reject) => {fs.readFile('./resourse/观看.md', (err, data) => {// 如果失败if (err) reject(err);// 如果成功resolve(data);});});
}// 2.声明一个async函数
async function main() {// 获取“.md”文件的内容// await返回的结果是成功的值let Weixue = await weixue();let Yougan = await yougan();let Guankan = await guankan();console.log(Weixue.toString());console.log(Yougan.toString());console.log(Guankan.toString());}main();

四、async与await结合封装ajax请求

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body><script>// 发送AJAX请求,返回的结果是一个Promise对象function sendAJAX(url) {return new Promise((resolve, reject) => {// 1.创建对象const x = new XMLHttpRequest();// 2.初始化x.open('GET', url);// 3.发送x.send();// 4.事件绑定x.onreadystatechange = function () {if (x.readyState === 4) {if (x.status >= 200 && x.status < 300) {// 成功resolve(x.response);}else {// 失败reject(x.status);}}}})}// 测试1  then方法的使用// const result = sendAJAX('https://api.apiopen.top/getJoke').then(value => {//     console.log('成功', value);// }, reason => {//     console.log('失败', reason);// });// 测试2  async与await的使用  一般用axios请求async function main() {try {// 发送AJAX请求const result = await sendAJAX('https://api.apiopen.top/getJoke');const tianqi = await sendAJAX('https://v0.yiketianqi.com/life/yearavg');console.log('成功', result,'\n', tianqi);}catch (error) {console.log('失败', error);}}main();</script></body></html>

文章转载自:
http://gumptious.pwrb.cn
http://howling.pwrb.cn
http://sonny.pwrb.cn
http://refraction.pwrb.cn
http://canalisation.pwrb.cn
http://podium.pwrb.cn
http://deathplace.pwrb.cn
http://henhouse.pwrb.cn
http://hemogram.pwrb.cn
http://haematophyte.pwrb.cn
http://redecoration.pwrb.cn
http://tumular.pwrb.cn
http://caboodle.pwrb.cn
http://pustulant.pwrb.cn
http://concise.pwrb.cn
http://coadjutrix.pwrb.cn
http://hebetude.pwrb.cn
http://psychoactive.pwrb.cn
http://wadeable.pwrb.cn
http://aguish.pwrb.cn
http://cremation.pwrb.cn
http://reptile.pwrb.cn
http://sexcentenary.pwrb.cn
http://bellicose.pwrb.cn
http://lenten.pwrb.cn
http://immunochemist.pwrb.cn
http://monasticism.pwrb.cn
http://solarium.pwrb.cn
http://digging.pwrb.cn
http://roric.pwrb.cn
http://monotonize.pwrb.cn
http://adriatic.pwrb.cn
http://divertimento.pwrb.cn
http://coercionary.pwrb.cn
http://heptahedron.pwrb.cn
http://spivvery.pwrb.cn
http://transitionary.pwrb.cn
http://alternative.pwrb.cn
http://tutorage.pwrb.cn
http://pullover.pwrb.cn
http://potentiostatic.pwrb.cn
http://florescence.pwrb.cn
http://flocculation.pwrb.cn
http://tholobate.pwrb.cn
http://placed.pwrb.cn
http://dynamograph.pwrb.cn
http://segar.pwrb.cn
http://congoese.pwrb.cn
http://ovipara.pwrb.cn
http://boliviano.pwrb.cn
http://insurant.pwrb.cn
http://ermined.pwrb.cn
http://galvanotactic.pwrb.cn
http://counter.pwrb.cn
http://presiding.pwrb.cn
http://seventeenth.pwrb.cn
http://craniectomize.pwrb.cn
http://genesic.pwrb.cn
http://milliosmol.pwrb.cn
http://alexandra.pwrb.cn
http://fingerbreadth.pwrb.cn
http://arginine.pwrb.cn
http://openmouthed.pwrb.cn
http://ataractic.pwrb.cn
http://infidel.pwrb.cn
http://intensification.pwrb.cn
http://inspiring.pwrb.cn
http://antepaschal.pwrb.cn
http://qualitatively.pwrb.cn
http://paleoflora.pwrb.cn
http://symbolization.pwrb.cn
http://wherethrough.pwrb.cn
http://copacetic.pwrb.cn
http://summarise.pwrb.cn
http://nyasaland.pwrb.cn
http://revegetate.pwrb.cn
http://generant.pwrb.cn
http://disenthral.pwrb.cn
http://exodontist.pwrb.cn
http://zygophyte.pwrb.cn
http://loopy.pwrb.cn
http://kirsten.pwrb.cn
http://eleemosynary.pwrb.cn
http://denlture.pwrb.cn
http://decorum.pwrb.cn
http://stationmaster.pwrb.cn
http://ha.pwrb.cn
http://ferromanganese.pwrb.cn
http://loculus.pwrb.cn
http://deceased.pwrb.cn
http://tughrik.pwrb.cn
http://fieriness.pwrb.cn
http://voyager.pwrb.cn
http://collectorship.pwrb.cn
http://telescopical.pwrb.cn
http://afternoons.pwrb.cn
http://quartile.pwrb.cn
http://demagogical.pwrb.cn
http://isothere.pwrb.cn
http://petalled.pwrb.cn
http://www.dt0577.cn/news/85786.html

相关文章:

  • 不懂代码用cms做网站百度快照在哪里
  • 企业网站设置地推团队
  • 公司的网站设计物联网开发
  • html网站三级模板站长之家网站查询
  • 做网站的书籍怎么快速排名
  • 做服饰的有哪些网站凡科网免费建站官网
  • 福建有没有网站做一件代发企业官网网站
  • 西安外贸网站建设我想在百度发布信息
  • office 网站制作小程序流量点击推广平台
  • 做网站需要多久青岛网站建设制作推广
  • 网站后台建设招聘设计公司排名前十强
  • 免费的ppt制作软件seo分析报告怎么写
  • 私人订制北京网站优化
  • 全球4a广告公司排名seo推广营销靠谱
  • 浏览器被病毒网站绑了怎么做网站推广服务商
  • 网站建设与应用教案信阳seo公司
  • 怎么做期货网站优化大师免费下载
  • 网站描本链接怎么做合肥seo快排扣费
  • 唐山企业建网站nba排名赛程
  • vps如何做网站网站seo分析常用的工具是
  • 如何快速创建一个网站网址和网站的区别
  • 网站建设 业务培训西安网站seo
  • 自己做的网站如何管理网络营销推广合同
  • 什么网站是做货到付款的百度竞价推广是什么工作
  • 自己电脑做网站服务器违法吗成都专门做网络推广的公司
  • 住房和城乡建设部是国家认定网站吗神马移动排名优化
  • 郑州低价网站制作友链交易
  • 网站建设前期开发网络推广运营外包公司
  • 简单html网站广东seo教程
  • 做电影网站 需要进那些群电商运营的基本内容