中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

第一接單網(wǎng)平臺(tái)seo營銷推廣

第一接單網(wǎng)平臺(tái),seo營銷推廣,網(wǎng)站優(yōu)化排名多少錢,電子商務(wù)網(wǎng)站模板html1、promise鏈?zhǔn)秸{(diào)用 /*** 目標(biāo):把回調(diào)函數(shù)嵌套代碼,改成Promise鏈?zhǔn)秸{(diào)用結(jié)構(gòu)* 需求:獲取默認(rèn)第一個(gè)省,第一個(gè)市,第一個(gè)地區(qū)并展示在下拉菜單中*/let pname axios({url: http://hmajax.itheima.net/api/province,}).t…

1、promise鏈?zhǔn)秸{(diào)用

/*** 目標(biāo):把回調(diào)函數(shù)嵌套代碼,改成Promise鏈?zhǔn)秸{(diào)用結(jié)構(gòu)* 需求:獲取默認(rèn)第一個(gè)省,第一個(gè)市,第一個(gè)地區(qū)并展示在下拉菜單中*/let pname = ''axios({url: 'http://hmajax.itheima.net/api/province',}).then(result => {pname = result.data.list[0]document.querySelector('.province').innerHTML = pname// then方法返回一個(gè)promise對(duì)象 此對(duì)象調(diào)用then中的result為此處返回的結(jié)果return axios({ url: 'http://hmajax.itheima.net/api/city', params: { pname } })}).then(result => {const cname = result.data.list[0]document.querySelector('.city').innerHTML = cnamereturn axios({ url: 'http://hmajax.itheima.net/api/area', params: { pname, cname } })}).then(result => {// 此處result為上面請(qǐng)求返回的promise對(duì)象console.log(result)})// let pname = ''// // 1. 得到-獲取省份Promise對(duì)象// axios({url: 'http://hmajax.itheima.net/api/province'}).then(result => {//   pname = result.data.list[0]//   document.querySelector('.province').innerHTML = pname//   // 2. 得到-獲取城市Promise對(duì)象//   return axios({url: 'http://hmajax.itheima.net/api/city', params: { pname }})// }).then(result => {//   const cname = result.data.list[0]//   document.querySelector('.city').innerHTML = cname//   // 3. 得到-獲取地區(qū)Promise對(duì)象//   return axios({url: 'http://hmajax.itheima.net/api/area', params: { pname, cname }})// }).then(result => {//   console.log(result)//   const areaName = result.data.list[0]//   document.querySelector('.area').innerHTML = areaName// })

2、事件循環(huán)請(qǐng)?zhí)砑訄D片描述
異步代碼交由指定的線程處理, 處理完畢后推入任務(wù)隊(duì)列, 當(dāng)主線程空閑時(shí)就會(huì)循環(huán)從任務(wù)隊(duì)列中取出異步代碼執(zhí)行請(qǐng)?zhí)砑訄D片描述
3、宏任務(wù)和微任務(wù)請(qǐng)?zhí)砑訄D片描述
promise本身是同步的,而then和catch回調(diào)函數(shù)是異步的

請(qǐng)?zhí)砑訄D片描述
例題:
請(qǐng)?zhí)砑訄D片描述

答案:1 7 5 6 2 3 4
請(qǐng)?zhí)砑訄D片描述
調(diào)用棧空閑時(shí),優(yōu)先清空微任務(wù)隊(duì)列中的回調(diào)

4、promise.all 靜態(tài)方法
什么時(shí)候使用:想合并多個(gè)promise對(duì)象,同時(shí)等待大家都成功的結(jié)果,然后做后續(xù)處理的場(chǎng)景
請(qǐng)?zhí)砑訄D片描述
請(qǐng)?zhí)砑訄D片描述

  <script>/*** 目標(biāo):掌握Promise的all方法作用,和使用場(chǎng)景* 業(yè)務(wù):當(dāng)我需要同一時(shí)間顯示多個(gè)請(qǐng)求的結(jié)果時(shí),就要把多請(qǐng)求合并* 例如:默認(rèn)顯示"北京", "上海", "廣州", "深圳"的天氣在首頁查看* code:* 北京-110100* 上海-310100* 廣州-440100* 深圳-440300*/// 1. 請(qǐng)求城市天氣,得到Promise對(duì)象const bjPromise = axios({ url: 'http://hmajax.itheima.net/api/weather', params: { city: '110100' } })const shPromise = axios({ url: 'http://hmajax.itheima.net/api/weather', params: { city: '310100' } })const gzPromise = axios({ url: 'http://hmajax.itheima.net/api/weather', params: { city: '440100' } })const szPromise = axios({ url: 'http://hmajax.itheima.net/api/weather', params: { city: '440300' } })// 2. 使用Promise.all,合并多個(gè)Promise對(duì)象const p = Promise.all([bjPromise, shPromise, gzPromise, szPromise])p.then(result => {// 注意:結(jié)果數(shù)組順序和合并時(shí)順序是一致console.log(result)const htmlStr = result.map(item => {return `<li>${item.data.data.area} --- ${item.data.data.weather}</li>`}).join('')document.querySelector('.my-ul').innerHTML = htmlStr}).catch(error => {console.dir(error)})</script>

5、axios返回的是一個(gè)promise對(duì)象,axios.then方法也返回一個(gè)新promise對(duì)象

<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script><script>const p = axios({url: 'http://hmajax.itheima.net/api/weather',params: { city: '110100' }})console.log(typeof p)const p2 = p.then(result => {console.log(result)})console.log(p2 === p)console.log(typeof p === typeof p2)</script>

在這里插入圖片描述
6、案例:
需求:同時(shí)展示數(shù)據(jù)

返回的是一個(gè)個(gè)promise對(duì)象組成的數(shù)組請(qǐng)?zhí)砑訄D片描述
${}中放一個(gè)表達(dá)式,map函數(shù)調(diào)用也是一個(gè)表達(dá)式
在模板字符串中如何體現(xiàn)循環(huán)操作

<script>//一級(jí) 二級(jí) 及所有商品要一起展示axios({url: 'http://hmajax.itheima.net/api/category/top'}).then(result => {// console.log(result)const arr = result.data.dataconst pArr = arr.map(item => {return axios({url: 'http://hmajax.itheima.net/api/category/sub',params: {id: item.id}})})//返回一個(gè)promise對(duì)象組成的數(shù)組const p = Promise.all(pArr)p.then(result => {// console.log(result)document.querySelector('.sub-list').innerHTML = result.map(item => {const itemData = item.data.dataconst children = itemData.children// console.log(children)return `<div class="item"><h3>${itemData.name}</h3><ul>${children.map(item => {return `<li><a href="javascript:;"><img src=${item.picture}><p>${item.name}</p></a></li>`}).join('')}</ul></div>`}).join('')})})// /**//  * 目標(biāo):把所有商品分類“同時(shí)”渲染到頁面上//  *  1. 獲取所有一級(jí)分類數(shù)據(jù)//  *  2. 遍歷id,創(chuàng)建獲取二級(jí)分類請(qǐng)求//  *  3. 合并所有二級(jí)分類Promise對(duì)象//  *  4. 等待同時(shí)成功后,渲染頁面// */// // 1. 獲取所有一級(jí)分類數(shù)據(jù)// axios({//   url: 'http://hmajax.itheima.net/api/category/top'// }).then(result => {//   console.log(result)//   // 2. 遍歷id,創(chuàng)建獲取二級(jí)分類請(qǐng)求//   const secPromiseList = result.data.data.map(item => {//     return axios({//       url: 'http://hmajax.itheima.net/api/category/sub',//       params: {//         id: item.id // 一級(jí)分類id//       }//     })//   })//   console.log(secPromiseList) // [二級(jí)分類請(qǐng)求Promise對(duì)象,二級(jí)分類請(qǐng)求Promise對(duì)象,...]//   // 3. 合并所有二級(jí)分類Promise對(duì)象//   const p = Promise.all(secPromiseList)//   p.then(result => {//     console.log(result)//     // 4. 等待同時(shí)成功后,渲染頁面//     const htmlStr = result.map(item => {//       const dataObj = item.data.data // 取出關(guān)鍵數(shù)據(jù)對(duì)象//       return `<div class="item">//     <h3>${dataObj.name}</h3>//     <ul>//       ${dataObj.children.map(item => {//         return `<li>//         <a href="javascript:;">//           <img src="${item.picture}">//           <p>${item.name}</p>//         </a>//       </li>`//       }).join('')}//     </ul>//   </div>`//     }).join('')//     console.log(htmlStr)//     document.querySelector('.sub-list').innerHTML = htmlStr//   })// })</script>
http://m.risenshineclean.com/news/61585.html

相關(guān)文章:

  • 漸變網(wǎng)站公眾號(hào)怎么推廣
  • 招商網(wǎng)站開發(fā)文檔整站優(yōu)化案例
  • 門戶網(wǎng)站是什么意思啊線上推廣方式
  • wordpress導(dǎo)航調(diào)用代碼湖南專業(yè)的關(guān)鍵詞優(yōu)化
  • 公司網(wǎng)站網(wǎng)址注冊(cè)和備案哪里找sem數(shù)據(jù)分析
  • 北京開放疫情最新消息關(guān)鍵詞優(yōu)化精靈
  • 網(wǎng)站做圖標(biāo)鏈接網(wǎng)站域名查詢地址
  • 表情包做舊網(wǎng)站百度競(jìng)價(jià)推廣賬戶
  • 網(wǎng)站建設(shè)藤設(shè)計(jì)廣告做到百度第一頁
  • 天津外貿(mào)網(wǎng)站建設(shè)公司如何優(yōu)化關(guān)鍵詞的方法
  • 公司做的網(wǎng)站入哪個(gè)會(huì)計(jì)科目怎么安裝百度
  • 建設(shè)個(gè)人商城網(wǎng)站seo優(yōu)化知識(shí)
  • 創(chuàng)業(yè)如何進(jìn)行網(wǎng)站建設(shè)路由優(yōu)化大師
  • 徐州建設(shè)工程交易網(wǎng)平臺(tái)官網(wǎng)網(wǎng)站seo搜索引擎優(yōu)化案例
  • 太原小程序開發(fā)定制學(xué)校seo推廣培訓(xùn)班
  • 中央人民政府網(wǎng)站網(wǎng)址百度圖片
  • 西安專業(yè)網(wǎng)站建設(shè)公司開創(chuàng)集團(tuán)與百度
  • wordpress 遠(yuǎn)程數(shù)據(jù)庫太原百度搜索排名優(yōu)化
  • 網(wǎng)站備案添加域名識(shí)圖找圖
  • 網(wǎng)站建設(shè)的優(yōu)點(diǎn)如何搭建自己的網(wǎng)站
  • 手把手教你做網(wǎng)站7seo推廣方案
  • 臨海市城鄉(xiāng)建設(shè)規(guī)劃局網(wǎng)站廣州搜發(fā)網(wǎng)絡(luò)科技有限公司
  • 萬站群cms百度入口提交
  • 用國外服務(wù)器做網(wǎng)站網(wǎng)絡(luò)宣傳怎么做
  • 怎么用ps做網(wǎng)站圖片能讓手機(jī)流暢到爆的軟件
  • 網(wǎng)上服裝定制網(wǎng)站seo優(yōu)化軟件有哪些
  • 提供手機(jī)自適應(yīng)網(wǎng)站建設(shè)優(yōu)化疫情防控 這些措施你應(yīng)該知道
  • 這是我自己做的網(wǎng)站嗎百度怎么發(fā)廣告
  • 旅游酒店網(wǎng)站建設(shè)三葉草gw9356
  • 網(wǎng)站維護(hù) 公司簡介網(wǎng)站免費(fèi)網(wǎng)站免費(fèi)