自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

鴻蒙的橫向滾動菜單和分組Group列表菜單和fetch請求加載聚合數(shù)據(jù)

系統(tǒng)
文章由鴻蒙社區(qū)產(chǎn)出,想要了解更多內(nèi)容請前往:51CTO和華為官方戰(zhàn)略合作共建的鴻蒙技術(shù)社區(qū)https://harmonyos.51cto.com/#zz

[[378172]]

 想了解更多內(nèi)容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.51cto.com/#zz

本文的項目是通過遠(yuǎn)程調(diào)用聚合數(shù)據(jù)制作一個新聞頁面.首先要明確以下幾點:

1.頁面加載的時候 用戶點擊加載瀏覽什么服務(wù)器就加載什么,若一下全部加載出來不僅對頁面布局有負(fù)擔(dān),而且對服務(wù)器的負(fù)載也很大,造成服務(wù)器資源浪費(fèi).

2.思路過程(以制作首頁為例): onInit首先加載拿到首頁數(shù)據(jù);用戶點擊那個菜單加載那個菜單的數(shù)據(jù).

項目過程如下:

1.導(dǎo)入鴻蒙的網(wǎng)絡(luò)請求模塊fetch (上篇文章也講到) 這里需要重點注意的是:一定要到config.json中去看有沒有配置二級域名 不然看不到數(shù)據(jù).例如我這里是v.juhe.cn 下圖:


2.因為鴻蒙沒有可視化窗口 ,因此我們可以制作一個調(diào)試可視化窗口.調(diào)試完成后 再將其去掉 . 這個窗口的目的僅是讓自己通過可視化窗口清楚明了的看到是否成功拿到數(shù)據(jù),便于我們更好的跟蹤和調(diào)試.(點擊事件changemenu跳轉(zhuǎn)到j(luò)s中 將當(dāng)前點擊的菜單項賦值給currentIndex就做制作一個調(diào)試窗口)具體代碼及標(biāo)注以下會詳細(xì)給出. 展示想過如下圖:

 

模擬器中的字樣來自于聚合數(shù)據(jù)給定的樣式:

js業(yè)務(wù)邏輯層:

  1. import fetch from '@system.fetch'
  2. export default { 
  3.     data: { 
  4.         title:''
  5.         currentIndex:0, 
  6.         type:""
  7.         bookdatas:[],  //申明一個數(shù)組 
  8.        menus:["首頁","新聞","影視","音樂","天氣","生活","體育","電競","娛樂","美食"
  9.     }, 
  10.     onInit() { 
  11.          
  12.  
  13.         fetch.fetch({ 
  14.             url:"http://v.juhe.cn/toutiao/index?type=top&key=401162c3e198047abc4d73d6f95aabbe"
  15.             //v.juhe.cn一定要到config.json中去看有沒有配置二級域名  
  16.             responseType:"json"
  17.             success:(resp)=>{ 
  18.                 let datas=JSON.parse(resp.data);   //轉(zhuǎn)換成json數(shù)據(jù)格式   
  19.                 this.title=datas.reason; 
  20.                 this.bookdatas=datas.result.data; 
  21.                
  22.  
  23.             } 
  24.  
  25.         } 
  26.  
  27.     }, 
  28.     changemenu(event){ 
  29.            let clickindex=event.index
  30.            this.currentIndex=clickindex ; //當(dāng)前點擊的菜單項賦值給currentIndex 
  31.            this.type=typeof clickindex; 
  32.         if(clickindex==0) 
  33.            { 
  34.  
  35.            } 
  36.          else if(clickindex==1) 
  37.           { 
  38.  
  39.           } 
  40.     } 

 頁面渲染:

  1. <div class="container"
  2.     <!--鴻蒙沒有橫向和垂直的滾頂視圖組件--> 
  3.     <tabs class="tabs" index="{{currentIndex}}" vertical="false" onchange="changemenu"
  4.         <tab-bar class="tab-bar" mode="scrollable"
  5.             <block for="{{menus}}"
  6.                 <text>{{$item}}</text> 
  7.             </block> 
  8.         </tab-bar> 
  9.         <tab-content class="tab-content" scrollable="true"
  10.             <div class="oneview"
  11.                 <list class="listview">              //運(yùn)用列表展示數(shù)據(jù) 
  12.                     <block for="{{bookdatas}}"
  13.                         <list-item class="list-item"
  14.                             <text>{{$item.title}}</text> 
  15.                         </list-item> 
  16.                     </block> 
  17.                 </list> 
  18.             </div> 
  19.             <div class="twoview"
  20.                 <text>two</text> 
  21.             </div> 
  22.         </tab-content> 
  23.     </tabs> 
  24.      <div class="info"
  25.          <text class="txtview">{{currentIndex}} </text>  //返回當(dāng)前標(biāo) 
  26.          <text class="txtview">{{type}} </text>   //返回當(dāng)前下表的數(shù)值類型 
  27.          <text class="txtview">{{title}} </text>   //是否成功獲取數(shù)據(jù) 
  28.      </div> 
  29. </div> 

 css屬性設(shè)置:

  1. .container{ 
  2.     width: 100%; 
  3.     height: 1200px; 
  4.     background-color: palegreen ; 
  5.     display: flex; 
  6.     flex-direction: column
  7. .tabs{ 
  8.     width: 100%; 
  9.  
  10. .tab-content{ 
  11.     width: 100%; 
  12.     height: 80%; 
  13.     background-color: green; 
  14. .oneview{ 
  15.     width: 100%; 
  16.     height: 100%; 
  17.     background-color: white; 
  18. .twoview{ 
  19.     width: 100%; 
  20.     height: 100%; 
  21.     background-color: skyblue; 
  22. .info{ 
  23.     width: 100%; 
  24.     height: 20%; 
  25.     border:1px solid red; 
  26. .txtview{ 
  27.     font-size: 50px; 
  28.     color: red; 
  29. .listview{ 
  30.     width: 100%; 
  31.     height: 100%; 
  32. .list-item{ 
  33.     width: 100%; 
  34.     height: 20%; 
  35.     border: 1px solid red; 

 最后再強(qiáng)調(diào)一點 在調(diào)用聚合數(shù)據(jù)的時候代碼的格式一定要和聚合給定的格式相同,通俗的來講就是例如:我這里想獲取的是是result中的data中的title的數(shù)據(jù)(見下圖) 因此我們同樣要將獲取的數(shù)組放到申明的bookdatas數(shù)組中

 

 最終效果圖如下:


這樣項目的大體框架就出來了 其他頁面也是如此.后續(xù)會繼續(xù)優(yōu)化頁面的布局.

©著作權(quán)歸作者和HarmonyOS技術(shù)社區(qū)共同所有,如需轉(zhuǎn)載,請注明出處,否則將追究法律責(zé)任。

想了解更多內(nèi)容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.51cto.com/#zz

 

責(zé)任編輯:jianghua 來源: 鴻蒙社區(qū)
相關(guān)推薦

2021-01-27 13:26:21

鴻蒙HarmonyOS應(yīng)用開發(fā)

2009-07-15 13:31:51

Swing菜單和菜單項

2015-10-20 15:58:28

彈力菜單android源碼

2014-12-31 15:59:55

彈力菜單

2021-07-21 05:31:39

Windows 11操作系統(tǒng)微軟

2022-03-04 08:00:00

Java Strea數(shù)據(jù)函數(shù)

2021-01-21 12:04:05

Windows 10UI界面微軟

2010-01-04 11:36:05

Ubuntu GRUB

2009-11-05 10:33:06

CSS菜單

2024-01-08 08:50:19

Vue3級聯(lián)菜單數(shù)據(jù)懶加載

2024-07-14 22:18:33

2011-09-02 10:03:40

jQuery滾動圖片

2022-07-20 11:13:05

前端JSONVue3

2024-12-09 10:08:43

2011-07-27 13:04:39

jQuery

2011-09-06 14:36:34

觸摸菜單ipad應(yīng)用電子點菜

2024-12-26 07:33:02

2015-02-26 18:18:15

動畫菜單Animation c

2009-06-19 08:29:36

Windows 7微軟操作系統(tǒng)

2021-01-28 14:34:35

鴻蒙HarmonyOS應(yīng)用開發(fā)
點贊
收藏

51CTO技術(shù)棧公眾號