偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

鴻蒙的JS開發(fā)部模式14:tabs組件通過Python遠程服務構建項目一

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

[[382675]]

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

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

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

1.DevEco Studio的最新版開發(fā)工具新增預覽和調(diào)試真的很好用.通過對鴻蒙的tabs和tab-bar組件,tab-content組件動態(tài)生成,通過fetch請求python flask服務構建,效果圖如下:


2.python的代碼如下,提供了遠程的web服務,同時通過反向代理服務器nginx提供圖片等靜態(tài)資源的服務:

  1. from  flask  import Flask 
  2. from flask  import jsonify 
  3. from  flask  import   request 
  4. import json 
  5.  
  6.  
  7. app=Flask(__name__) 
  8.  
  9.  
  10. @app.route("/data"
  11. def  execData(): 
  12.     print("用戶發(fā)起data的請求,執(zhí)行execData方法"
  13.  
  14.     data1=("許金扉","李永毅","昌立昊"
  15.  
  16.     return jsonify(data1) 
  17.  
  18. @app.route("/querybyname",methods=["POST"]) 
  19. def  queryByName(): 
  20.     if request.method == 'POST'
  21.        print("用戶發(fā)起querybyname的請求,執(zhí)行queryByName方法"
  22.        #data2={"許金扉":"一個女學生","李永毅":"一個揚州的男學生","昌立昊":"一個南京的男學生"
  23.        data2 = {"許金扉":{"text":"女學生","img":"common/customer.png"}, 
  24.                 "李永毅": {"text":"男學生","img":"common/emp.png"}, "昌立昊": {"text":"男學生","img":"common/emp.png"}} 
  25.        # name=request.form.get("cname"
  26.        # print(name
  27.  
  28.        info=request.get_data(as_text=True
  29.        print(info) 
  30.        print(type(info)) 
  31.        name=json.loads(info).get("cname"
  32.        info1=data2.get(name
  33.  
  34.        return jsonify(info1) 
  35.  
  36.  
  37. @app.route("/loadmenu",methods=["GET"]) 
  38. def  loadMenu(): 
  39.     if  request.method=="GET"
  40.         print("加載首頁菜單"
  41.  
  42.         menudatas=[{"text":"首頁","selectIcon":"http://lixin.free.idcfengye.com/images/ones.png"
  43.                     "icon":"http://lixin.free.idcfengye.com/images/oneu.png"}, 
  44.                    {"text":"分類","selectIcon":"http://lixin.free.idcfengye.com/images/cs.png"
  45.                     "icon":"http://lixin.free.idcfengye.com/images/cu.png"}, 
  46.                    {"text":"閱讀","selectIcon":"http://lixin.free.idcfengye.com/images/rs.png"
  47.                     "icon":"http://lixin.free.idcfengye.com/images/ru.png"}, 
  48.                    {"text":"我的","selectIcon":"http://lixin.free.idcfengye.com/images/mys.png"
  49.                     "icon":"http://lixin.free.idcfengye.com/images/myu.png"}] 
  50.  
  51.  
  52.         return  jsonify(menudatas) 
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. if  __name__=="__main__"
  60.     app.run(debug=True,port=8500) 

 3.鴻蒙的遠程請求python flask服務,需要使用內(nèi)網(wǎng)穿透工具


4.同時啟動nginx服務和ngrok的內(nèi)網(wǎng)穿透



5.鴻蒙的業(yè)務邏輯層通過配置網(wǎng)絡權限和域名安全審核


5.鴻蒙js的業(yè)務邏輯層代碼

  1. import fetch from '@system.fetch'
  2. import prompt from '@system.prompt'
  3. export default { 
  4.     data: { 
  5.         title: 'World'
  6.         currentIndex:0, 
  7.         menudatas:[] 
  8.     }, 
  9.     onInit(){ 
  10.  
  11.  
  12.  
  13.         fetch.fetch({ 
  14.            url:"http://aeawqk.natappfree.cc/loadmenu"
  15.             method:"GET"
  16.             responseType:"json"
  17.             success:(resp)=> 
  18.             { 
  19.                 this.menudatas=JSON.parse(resp.data); 
  20.  
  21.  
  22.             } 
  23.  
  24.  
  25.         }); 
  26.     }, 
  27.     onShow(){ 
  28.         prompt.showToast({ 
  29.             message:"正在加載數(shù)據(jù),請稍后"
  30.             duration:5000 
  31.  
  32.         }); 
  33.     }, 
  34.     changeview(e) 
  35.     { 
  36.         let  cIndex=e.index
  37.  
  38.         this.currentIndex=cIndex; 
  39.  
  40.  
  41.     } 

 6.視圖層代碼

  1. <div class="container"
  2.     <tabs  class="tabs" index="{{currentIndex}}"  onchange="changeview" vertical="false" > 
  3.         <tab-bar class="tab-bar"  mode="fixed"
  4.             <block  for="{{menudatas}}"
  5.                 <div  class="menuview"
  6.                     <image  class="cimg"  src="{{currentIndex==$idx?$item.selectIcon:$item.icon}}"></image> 
  7.                     <text  class="{{currentIndex==$idx?'stxt':'dtxt'}}">{{$item.text}}</text> 
  8.                 </div> 
  9.             </block> 
  10.         </tab-bar> 
  11.  
  12.         <tab-content class="tab-content"
  13.             <div  class="oneview"
  14.  
  15.             </div> 
  16.             <div  class="twoview"
  17.  
  18.             </div> 
  19.             <div  class="threeview"
  20.  
  21.             </div> 
  22.             <div  class="fourview"
  23.  
  24.             </div> 
  25.  
  26.         </tab-content> 
  27.  
  28.     </tabs> 
  29. </div> 

7.樣式代碼

  1. .container { 
  2.     display: flex; 
  3.     flex-direction: column
  4.     width: 100%; 
  5. .tabs{ 
  6.     width: 100%; 
  7. .tab-bar{ 
  8.     width: 100%; 
  9.     height: 12%; 
  10.     border-top: 10px  solid  silver; 
  11.     position: fixed; 
  12.     left: 0px; 
  13.     bottom: 0px; 
  14.     z-index:999; 
  15.     background-color: snow; 
  16.  
  17. .menuview{ 
  18.     width: 100%; 
  19.     height: 100%; 
  20. /**border: 5px  solid  black;**/ 
  21.     display: flex; 
  22.     flex-direction: column
  23.     align-items: center; 
  24.     padding: 15px; 
  25. .cimg{ 
  26.     width: 70px; 
  27.     height: 70px; 
  28. .tab-content{ 
  29.     width: 100%; 
  30.  
  31. .oneview{ 
  32.     width: 100%; 
  33.     height: 100%; 
  34.     background-color: palegreen; 
  35. .twoview{ 
  36.     width: 100%; 
  37.     height: 100%; 
  38.     background-color: palegoldenrod; 
  39. .threeview{ 
  40.     width: 100%; 
  41.     height: 100%; 
  42.     background-color: papayawhip; 
  43. .fourview{ 
  44.     width: 100%; 
  45.     height: 100%; 
  46.     background-color: powderblue; 
  47. .stxt{ 
  48.     color: black; 
  49. .dtxt{ 
  50.     color: silver; 

 8.底部菜單欄通過三元運算符,進行切換,效果如下:

 

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

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

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

 

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

2021-03-09 09:35:09

鴻蒙HarmonyOS應用開發(fā)

2021-03-02 14:34:48

鴻蒙HarmonyOS應用開發(fā)

2021-02-26 14:13:48

鴻蒙HarmonyOS應用開發(fā)

2021-02-20 12:34:53

鴻蒙HarmonyOS應用開發(fā)

2017-07-17 15:50:17

微服務Docker架構

2021-04-23 16:08:08

鴻蒙HarmonyOS應用

2009-06-01 19:40:37

云計算 tivoli

2018-01-31 15:45:07

前端Vue.js組件

2024-05-09 09:01:03

2015-04-14 11:10:22

PaaSCloudFoundrBuildpack

2020-11-11 11:56:05

HarmonyOS

2021-01-22 17:23:32

鴻蒙HarmonyOS應用

2018-08-22 18:16:47

2011-06-28 10:42:38

Windows 8開發(fā)部門DevX

2020-09-01 13:10:42

JavaScript開發(fā) 技巧

2021-03-19 17:42:01

鴻蒙HarmonyOS應用開發(fā)

2023-07-17 16:13:21

組件模塊開發(fā)的鴻蒙

2013-06-08 15:04:24

醫(yī)療信息化華為

2019-11-22 23:34:26

iOS 13蘋果iOS系統(tǒng)

2023-07-26 10:21:26

服務端組件客戶端
點贊
收藏

51CTO技術棧公眾號