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

鴻蒙的遠程交互組件應用及微信小程序的遠程交互組件應用

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

[[377872]]

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

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

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

注:鴻蒙的遠程交互組件應用相對復雜 ,訪問網(wǎng)絡時,首先要配置網(wǎng)絡權限,華為官方文檔有問題,在此引用我老師配置的模板,見附件

過程:1.導入鴻蒙的網(wǎng)絡請求模塊fetch

         2.發(fā)起對服務器的請求(在這過程中需要用JSON.parse將括號中的數(shù)據(jù)轉換成json數(shù)據(jù)格式,具體見代碼中標注)

js業(yè)務邏輯層

  1.  //導入鴻蒙的網(wǎng)絡請求模塊fetch 
  2. import fetch from '@system.fetch'
  3. export default { 
  4.     data: { 
  5.         title: 'World'
  6.         currentTime:''
  7.         temperature1:''
  8.         text:''
  9.  
  10.     }, 
  11.         onInit() { 
  12.             //發(fā)起對心知天氣服務器的請求 
  13.           fetch.fetch({ 
  14.               url:'https://api.seniverse.com/v3/weather/now.json?key=S0YbU_VLcvXz-4LZx&location=成都&language=zh-Hans&unit=c'
  15.               responseType:'json'
  16.               success:(resp)=>{ 
  17.                   //JSON.parse(字符串)轉換成json數(shù)據(jù)格式 
  18.                   let weatherInfo=JSON.parse(resp.data); 
  19.                   this.currentTime=weatherInfo.results[0].last_update; 
  20.                   this.text=weatherInfo.results[0].now.text; 
  21.                   this.temperature1=weatherInfo.results[0].now.temperature; 
  22.               } 
  23.           }); 
  24.         } 

 渲染層

  1. <div class="container"
  2.     <text class="time"
  3.        {{currentTime}}{{temperature1}} 
  4.     </text> 
  5.     <text class="time"
  6.       {{temperature1}} 
  7.     </text> 
  8.     <text class="time"
  9.         {{text}} 
  10.     </text> 
  11. </div> 

  css樣式屬性設置

  1. .container { 
  2.     display: flex; 
  3.     justify-content: center; 
  4.     align-items: center; 
  5.     left: 0px; 
  6.     top: 0px; 
  7.     width: 454px; 
  8.     height: 454px; 
  9. .time { 
  10.     font-size: 50px; 
  11.     text-align: center; 
  12.     width: 200px; 
  13.     height: 1200px; 

 最終效果呈現(xiàn):


微信小程序的遠程交互應用:

js業(yè)務邏輯層

  1. // pages/images/weather/weather.js 
  2. Page({ 
  3.  
  4.   /** 
  5.    * 頁面的初始數(shù)據(jù) 
  6.    */ 
  7.   data: { 
  8.     weatherInfo:{}, 
  9.     nextweatherInfo:{} 
  10.  
  11.   }, 
  12.  
  13.   /** 
  14.    * 生命周期函數(shù)--監(jiān)聽頁面加載 
  15.    */ 
  16.   onLoad: function (options) { 
  17.     //微信小程序請求天氣 
  18.      wx.request({ 
  19.        url: 'https://api.seniverse.com/v3/weather/now.json?key=S0YbU_VLcvXz-4LZx&location=成都&language=zh-Hans&unit=c'
  20.        success:(resp)=>{ 
  21.             let info=resp.data; 
  22.             console.log(info);  
  23.             this.setData({weatherInfo:info}) 
  24.        } 
  25.      }) 
  26.      //微信小程序請求生活指數(shù) 
  27.      wx.request({ 
  28.        url: 'https://api.seniverse.com/v3/life/suggestion.json?key=S0YbU_VLcvXz-4LZx&location=成都&language=zh-Hans'
  29.        success:(resp )=>{  
  30.          let live=resp.data 
  31.            console.log(live) 
  32.        } 
  33.  
  34.      }) 
  35.      //微信請求未來三天氣預報 
  36.      wx.request({ 
  37.        url: 'https://api.seniverse.com/v3/weather/daily.json?key=S0YbU_VLcvXz-4LZx&location=成都&language=zh-Hans&unit=c&start=-1&days=5'
  38.        success:(resp)=>{ 
  39.          let time=resp.data; 
  40.          console.log(time
  41.          this.setData({nextweatherInfo:time.results[0].daily}) 
  42.  
  43.        } 
  44.      }) 
  45.  
  46.   }, 
  47.  
  48.   /** 
  49.    * 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成 
  50.    */ 
  51.   onReady: function () { 
  52.  
  53.   }, 
  54.  
  55.   /** 
  56.    * 生命周期函數(shù)--監(jiān)聽頁面顯示 
  57.    */ 
  58.   onShow: function () { 
  59.  
  60.   }, 
  61.  
  62.   /** 
  63.    * 生命周期函數(shù)--監(jiān)聽頁面隱藏 
  64.    */ 
  65.   onHide: function () { 
  66.  
  67.   }, 
  68.  
  69.   /** 
  70.    * 生命周期函數(shù)--監(jiān)聽頁面卸載 
  71.    */ 
  72.   onUnload: function () { 
  73.  
  74.   }, 
  75.  
  76.   /** 
  77.    * 頁面相關事件處理函數(shù)--監(jiān)聽用戶下拉動作 
  78.    */ 
  79.   onPullDownRefresh: function () { 
  80.  
  81.   }, 
  82.  
  83.   /** 
  84.    * 頁面上拉觸底事件的處理函數(shù) 
  85.    */ 
  86.   onReachBottom: function () { 
  87.  
  88.   }, 
  89.  
  90.   /** 
  91.    * 用戶點擊右上角分享 
  92.    */ 
  93.   onShareAppMessage: function () { 
  94.  
  95.   } 
  96. }) 

 渲染層

  1. <!--pages/images/weather/weather.wxml--> 
  2. <text>{{weatherInfo.results[0].last_update}}{{weatherInfo.results[0].location.name}}{{weatherInfo.results[0].now.text}}{{weatherInfo.results[0].now.temperature}}</text> 
  3. <view class="margin"></view
  4. <view class="top"
  5.   <block wx:for="{{nextweatherInfo}}"
  6.     <view class="three"
  7.       <view
  8.          <text class="txt1">{{item.date}}</text> 
  9.       </view
  10.       <view
  11.         <text class="txt1">{{item.text_day}}</text> 
  12.       </view
  13.       <view > 
  14.         <text class="txt1">{{item.wind_direction}}</text> 
  15.       </view
  16.  
  17.     </view
  18.   </block> 
  19. </view

 wxss樣式屬性設置

  1. /* pages/images/weather/weather.wxss */ 
  2. .margin{ 
  3.   width: 100%; 
  4.   height: 30px; 
  5.   background-color: rgb(56, 168, 202); 
  6. .top
  7.   width: 100%; 
  8.   height: 50vh; 
  9.   display: flex; 
  10.   flex-direction: row; 
  11.   justify-content: center; 
  12.   margin: 5px; 
  13. .three{ 
  14.   width: 27%; 
  15.   height: 50%; 
  16.   border: 1px solid blue; 
  17.   margin: 5px; 
  18.   
  19. .txt1{ 
  20.   font-weight: bold; 
  21.   font: size 15px; 
  22.  

 最終效果呈現(xiàn):


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

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

https://harmonyos.51cto.com/#zz想了解更多內(nèi)容,請訪問:

 【編輯推薦】

 

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

2010-01-25 16:58:53

Android組件交互

2017-05-08 15:03:07

微信小程序開發(fā)實戰(zhàn)

2013-12-08 22:02:24

手勢交互交互設計交互體驗

2022-05-19 15:59:23

組件焦點鴻蒙

2023-01-05 09:01:05

UI組件庫微信

2021-02-20 09:52:02

鴻蒙HarmonyOS應用開發(fā)

2013-02-19 10:47:17

情感交互產(chǎn)品交互趨勢

2011-09-01 15:54:10

app應用

2013-01-17 15:51:42

Android開發(fā)應用程序組件

2011-05-10 10:25:22

MIDletBlackBerry

2021-02-23 09:52:42

鴻蒙HarmonyOS應用開發(fā)

2021-02-26 15:10:00

前端React組件交互

2009-08-20 10:12:59

Flex Alert組

2014-05-27 14:16:08

AndroidActivitysingleTask

2014-05-27 15:07:07

AndroidActivitysingleTask

2014-05-27 15:11:20

AndroidActivitysingleTask

2014-05-27 15:17:46

AndroidActivitysingleTask

2014-05-27 14:44:26

AndroidActivitysingleTask

2014-05-27 14:28:25

AndroidActivitysingleTask

2014-05-27 14:12:49

AndroidActivitysingleTask
點贊
收藏

51CTO技術棧公眾號