鸿蒙JS开发6 鸿蒙的提示框、对话框和提示菜单的应用

开发 前端
本文主要描述对鸿蒙幻灯片组件、跑马灯组件、提示框、提示菜单、页面跳转以及对话框的应用

[[379017]]

想了解更多内容,请访问:

51CTO和华为官方战略合作共建的鸿蒙技术社区

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

本文主要描述对鸿蒙幻灯片组件、跑马灯组件、提示框、提示菜单、页面跳转以及对话框的应用

幻灯片组件:<image-animator>

视图及样式:

  1. <div class="container"
  2.     <div class="c1"
  3.         <!--幻灯片组件--> 
  4.         <image-animator class="image-animator" duration="10s" fixedsize="false" images="{{imagesDatas}}"
  5.         </image-animator> 
  6.     </div> 
  7. </div> 

  1. .container { 
  2.     width: 100%; 
  3.     height: 1500px; 
  4.     display: flex; 
  5.     flex-direction: column
  6. .c1{ 
  7.     width: 100%; 
  8.     height: 35%; 
  9. .image-animator{ 
  10.     width: 100%; 
  11.     height: 100%; 

 业务逻辑层通过fetch请求向nginx反向代理服务请求所需数据

  1. import fetch from '@system.fetch'
  2.  
  3. export default { 
  4.     data: { 
  5.         imagesDatas:[] 
  6.         
  7.     }, 
  8.  
  9.     onInit(){ 
  10.         fetch.fetch({ 
  11.             //url对应的地址为通过内网穿透工具natapp映射出的nginx反向代理服务的地址 
  12.             url:'http://ibk3v7.natappfree.cc/text/images0.json'
  13.             responseType:"json"
  14.             success:(resp)=>{ 
  15.                 let datas = JSON.parse(resp.data); 
  16.                 this.imagesDatas = datas.imagedatas; 
  17.  
  18.             } 
  19.         }); 
  20.     } 

 images0.json文件中定义的数据:


效果图(图片是可以自动播放的):


跑马灯组件:<marquee>

  1. <div class="container"
  2.     <marquee>金牛辞旧岁,万里贺新春。让快乐与你同行,让健康与你相伴,将美好与团圆满满托付于你</marquee> 
  3. </div> 

 效果图:


鸿蒙的弹出菜单、提示框、页面跳转的应用

视图和样式:

  1. <div class="container"
  2.     <div class="c1"
  3.         <!--幻灯片组件--> 
  4. <!--        <image-animator class="image-animator" duration="10s" fixedsize="false" images="{{imagesDatas}}">--> 
  5. <!--        </image-animator>--> 
  6.     </div> 
  7.     <div class="c2"
  8.         <button onclick="clickbutton">我是个点击按钮</button> 
  9.     </div> 
  10.     <!--弹出菜单--> 
  11.     <menu id="menuid" onselected="selectmenu"
  12.         <option value="aaa">aaa</option
  13.         <option value="bbb">bbb</option
  14.         <option value="ccc">ccc</option
  15.     </menu> 
  16.  
  17. </div> 

  1. .container { 
  2.     width: 100%; 
  3.     height: 1500px; 
  4.     display: flex; 
  5.     flex-direction: column
  6. .c1{ 
  7.     width: 100%; 
  8.     height: 35%; 
  9. .c2{ 
  10.     width: 100%; 
  11.     height: 8%; 

 业务逻辑层:

  1. import prompt from '@system.prompt'
  2. import router from '@system.router'
  3. export default { 
  4.     data: { 
  5.     }, 
  6.  
  7.     //点击按钮触发 弹出显示菜单 事件 
  8.     clickbutton(){ 
  9.         //显示id为 menuid 的菜单,此菜单出现位置默认为屏幕左上角原点,可通过在show()中添加坐标来改变 
  10.         //this.$element("menuid").show(); 
  11.  
  12.         this.$element("menuid").show({ 
  13.             x:100, 
  14.             y:550 
  15.         }); 
  16.  
  17.     }, 
  18.     //选中弹出菜单中的项触发事件 
  19.     selectmenu(e){ 
  20.         let path = e.value; 
  21.         //鸿蒙的提示框 
  22.         prompt.showToast({ 
  23.             message:path 
  24.         }); 
  25.  
  26.         if(path=="aaa"){ 
  27.             //鸿蒙提供的页面跳转 
  28.             router.push({ 
  29.                 uri:'pages/aaa/aaa' 
  30.             }); 
  31.  
  32.         }else if(path=="bbb"){ 
  33.             router.push({ 
  34.                uri:'pages/bbb/bbb' 
  35.             }); 
  36.         }else if(path=="ccc"){ 
  37.             router.push({ 
  38.                uri:'pages/ccc/ccc' 
  39.             }); 
  40.         } 
  41.     } 

 效果图(点击按钮弹出菜单后点击对应菜单触发跳转页面的事件):


鸿蒙的对话框

视图和样式:

  1. <div class="container"
  2.     <button onclick="onclick">我是另一个点击按钮</button> 
  3. </div> 

 逻辑层:

  1. import prompt from '@system.prompt'
  2. export default { 
  3.     data: { 
  4.  
  5.     }, 
  6.     onclick(){ 
  7.         //鸿蒙的对话框 
  8.         prompt.showDialog({ 
  9.             title:"对话框"
  10.             message:"确定删除这条消息么?"
  11.             buttons:[{"text":"确定","color":"#00E5EE"}, 
  12.                      {"text":"取消","color":"#00E5EE"}], 
  13.             success:function(e){ 
  14.                 if(e.index==0){ 
  15.                     //鸿蒙的提示框 
  16.                     prompt.showToast({ 
  17.                         message:"您点击了确定" 
  18.                     }); 
  19.                 }else if(e.index==1){ 
  20.                     prompt.showToast({ 
  21.                         message:"您点击了取消" 
  22.                     }); 
  23.                 } 
  24.             } 
  25.         }); 
  26.     } 

 效果图:

 

©著作权归作者和HarmonyOS技术社区共同所有,如需转载,请注明出处,否则将追究法律责任。

想了解更多内容,请访问:

51CTO和华为官方战略合作共建的鸿蒙技术社区

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

 

责任编辑:jianghua 来源: 鸿蒙社区
相关推荐

2021-01-29 09:48:17

鸿蒙HarmonyOS应用开发

2011-07-01 11:33:00

Qt 模态 非模态

2015-10-29 11:13:23

iOS9使用框

2012-12-03 10:47:54

WebJQuery控件

2011-07-21 15:50:42

jQuery Mobi页面对话框

2011-11-23 09:47:36

Winform

2021-01-27 13:26:21

鸿蒙HarmonyOS应用开发

2021-04-06 20:57:31

JavaScript弹出框窗口

2011-07-22 15:32:53

iPhone 按钮 对话框

2009-12-11 15:35:50

PHP弹出对话框

2009-12-28 14:32:31

WPF窗体对话框

2009-12-28 13:47:35

WPF对话框

2010-08-05 10:42:41

Android开发Android高级编程

2010-01-28 16:55:26

Android对话框

2021-07-11 07:34:23

Windows 11操作系统微软

2010-01-11 09:33:32

VB.NET对话框调用

2009-12-29 15:24:48

WPF对话框

2011-05-20 16:49:21

VB.NET

2009-11-03 09:21:26

Visual Stud

2019-01-09 11:30:07

Windows10空白对话框命令
点赞
收藏

51CTO技术栈公众号