当前位置:主页 > 查看内容

鸿蒙提示框,对话框,路由跳转页面,跑马灯,幻灯片及list组件的

发布时间:2021-06-21 00:00| 位朋友查看

简介:想了解更多内容,请访问: 51CTO和华为官方战略合作共建的鸿蒙技术社区 https://harmonyos.51cto.com/#zz 幻灯片控件:image-animator/image-animator 跑马灯控件: marquee/marquee 弹出提示框:prompt.showToast() 弹出对话框:prompt.showDialog() 在制作提示……

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

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

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

幻灯片控件:<image-animator></image-animator>

跑马灯控件: <marquee></marquee>

弹出提示框:prompt.showToast()

弹出对话框:prompt.showDialog()

在制作提示框的时候,首先制作一个菜单栏选项,弹出菜单栏仅有当调试点击后才触发显示出来 不占用原有视图空间.弹出菜单栏的位置默认以(0,0)为基准点,为了更好的用户体验,也可以自行设置弹出位置(如下图)


介绍一种跳转页面新方法:路由跳转页面(具体见代码): import router from '@system.router'; //通过路由跳转页面

router.push({ uri: 'pages/jumpone/jumpone'}) //路由的方法

主页面的js业务逻辑层:

  1. import prompt from '@system.prompt'
  2. import router from '@system.router';  //路由  通过路由跳转页面 
  3. export default { 
  4.     data: { 
  5.         title: 'World'
  6.         imgdatas:[{ 
  7.                       "src":"http://ttjib3.natappfree.cc/images/12.jpeg" 
  8.                   }, 
  9.                   { 
  10.                       "src":"http://ttjib3.natappfree.cc/images/13.jpg" 
  11.                   }, 
  12.                   { 
  13.                      "src":"http://ttjib3.natappfree.cc/images/14.jpg" 
  14.                   }, 
  15.                    { 
  16.                       "src":"http://ttjib3.natappfree.cc/images/15.jpg" 
  17.                   }, 
  18.                   { 
  19.                    "src":"http://ttjib3.natappfree.cc/images/16.png" 
  20.                }] 
  21.     }, 
  22.         showmenu() { 
  23.             //弹出显示菜单    首先要获取这个组件用  this.$element 
  24.  
  25.             //this.$element("menueone").show(); 
  26.  
  27.             //弹出的具体位置 默认时以(0,0)为基准点 
  28.              this.$element("menueone").show({ 
  29.                x:0, 
  30.                  y:0 
  31.            }); 
  32.         }, 
  33.         changemenu(e) { 
  34.             let name = e.value //这里的value就是hml中的value 
  35.             //鸿蒙的提示框 
  36.             prompt.showToast({ 
  37.                 message:name 
  38.             }); 
  39.             if (name == "太和殿"
  40.             { 
  41.                 router.push({                   //路由的方法 
  42.                     uri: 'pages/jumpone/jumpone' 
  43.                 }); 
  44.             } 
  45.             else if(name == "养心殿"
  46.             { 
  47.                 router.push({                    //路由的方法 
  48.                     uri: 'pages/jumptwo/jumptwo' 
  49.                 }); 
  50.             } 
  51.             else if(name == "乾清宫"
  52.             { 
  53.                 router.push({                     //路由的方法 
  54.                     uri: 'pages/jumpthree/jumpthree' 
  55.                 }); 
  56.             } 
  57.         } 
  58.  

 主页面视图层:

  1. <div class="container"
  2.    <div class="topview"
  3.        <!--幻灯片组件--> 
  4.        <image-animator class="image-animator" duration="5s" fixedsize="false" images="{{imgdatas}}"
  5.        </image-animator> 
  6.    </div> 
  7.     <div class="contentview"
  8.         <button onclick="showmenu">菜单</button> 
  9.     </div> 
  10.     <menu id="menueone" onselected="changemenu"
  11.         <option value="太和殿">太和殿</option
  12.         <option value="养心殿">养心殿</option
  13.         <option value="乾清宫">乾清宫</option
  14.     </menu> 
  15. </div> 

主页面css属性设置:

  1. .container { 
  2.  
  3.     width:100%; 
  4.     height: 1200px; 
  5.     display: flex; 
  6.     flex-direction: column
  7.     background-color: skyblue; 
  8. .topview{ 
  9.     width: 100%; 
  10.     height: 30%; 
  11.     border-bottom: 1px solid blue; 
  12. .image-animator{ 
  13.     width: 100%; 
  14.     height: 100%; 
  15. .contentview{ 
  16.     width: 100%; 
  17.     height: 10%; 
  18.     background-color: white; 

跳转页面一的js业务逻辑层:

  1. import prompt from '@system.prompt'
  2.  
  3. export default { 
  4.     data: { 
  5.         title: 'World' 
  6.     }, 
  7.     changmes() { 
  8.         //1.弹出提示框 
  9.         // prompt.showToast() 
  10.         //2.弹出对话框 
  11.         prompt.showDialog({ 
  12.             title:"问题"
  13.             message:"你今年是否有600岁?"
  14.             buttons:[{"text":"是","color":"#000000"},{"text":"否","color":"#000000"}], 
  15.             //用successs追踪对话框 
  16.             success:function(data){ 
  17.                    if(data.index==0){ 
  18.                        prompt.showToast({ 
  19.                            message:"你点击了是按钮" 
  20.                        }) 
  21.                    } 
  22.                    if(data.index==1){ 
  23.                        prompt.showToast({ 
  24.                            message:"你点击了否按钮" 
  25.                        }) 
  26.                    } 
  27.             } 
  28.         }) 
  29.     } 

 跳转页面一的视图层:

  1. <div class="container"
  2.        <button onclick="changmes">太和殿</button> 
  3. </div> 

跳转页面二的视图层:

  1. <div class="container"
  2.   <marquee> 
  3.       最是一年春好处,绝胜烟柳满皇都 
  4.   </marquee> 
  5. </div> 

跳转页面三的js业务逻辑层:

  1. import router from '@system.router'
  2. export default { 
  3.     data: { 
  4.         title: 'World'
  5.         listdatas:[{"cname":"故宫典藏","cimg":"/common/gugong.png","lname":[{"fname":"宫廷人物","icon":"/common/renwu.png"},{"fname":"宫廷典制","icon":"/common/gugong.png"},{"fname":"宫廷文创","icon":"/common/gongwenhua.png"},{"fname":"宫廷建筑","icon":"/common/gu.png"}]}, 
  6.                    {"cname":"故宫文创","cimg":"/common/gugong.png","lname":[]}, 
  7.                    {"cname":"故宫建筑","cimg":"/common/gugong.png","lname":[]}, 
  8.                    {"cname":"故宫历史","cimg":"/common/gugong.png","lname":[]} 
  9.         ] 
  10.     }, 
  11.     changemenu(e){ 
  12.          router.push({ 
  13.              uri:'pages/gugongwenchuang/gugongwenchuang' 
  14.          }) 
  15.     } 

跳转页面三的视图层:

  1. <div class="container"
  2.     <list class="listview"
  3.         <block for="{{listdatas}}"
  4.             <list-item-group class="group">      <!--高度不需要给出 会自适应大小--> 
  5.                 <list-item class="listitem"
  6.                     <image class="img1" src="{{$item.cimg}}"></image> 
  7.                     <text class="txt1">{{$item.cname}}</text> 
  8.                 </list-item> 
  9.                 <block for="{{(cindx,cvalue) in $item.lname}}"
  10.                     <list-item class="listitem1" onclick="changemenu"
  11.                         <image class="img1" src="{{cvalue.icon}}"></image> 
  12.                         <text class="txt2">{{cvalue.fname}}</text> 
  13.                     </list-item> 
  14.                 </block> 
  15.             </list-item-group
  16.         </block> 
  17.     </list> 
  18. </div> 

跳转页面三的css属性设置:

  1. .container { 
  2.     width: 100%; 
  3.     height: 1200px; 
  4.     display: flex; 
  5.     flex-direction: column
  6.     background-color: skyblue; 
  7. .listview{ 
  8.     width: 100%; 
  9.     height: 100%; 
  10. .group
  11.     width: 100%; 
  12. .listitem{ 
  13.     width: 100%; 
  14.     height: 25%; 
  15.     display: flex; 
  16.     justify-content:center; 
  17.     align-items: center; 
  18. .img1{ 
  19.     width: 80px; 
  20.     height: 80px; 
  21. .txt1{ 
  22.     font-size: 45px; 
  23.     font-weight: bold; 
  24.     font-family: sans-serif; 
  25.     margin-left: 70px; 
  26. .txt2{ 
  27.     font-size: 35px; 
  28.  
  29.     font-family: sans-serif; 
  30.     margin-left: 70px; 
  31. .listitem1{ 
  32.     width: 100%; 
  33.     height: 18%; 
  34.     display: flex; 
  35.     justify-content:center; 
  36.     align-items: center; 

 效果图如下,效果视频已上传专栏(HarmonyOS开发从0到1) https://harmonyos.51cto.com/column/35

 


 


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

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

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

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


本文转载自网络,原文链接:https://harmonyos.51cto.com/#zz
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!

推荐图文

  • 周排行
  • 月排行
  • 总排行

随机推荐