wepy底部导航栏效果

不念不忘少年蓝@ 2022-03-01 01:46 462阅读 0赞

文档

  • wepy快速指南
  • 小程序框架wepy开发文档
  • wepy开源
  • wepy官方文档

wepy是腾讯自己开发的框架,作用主要是提高开发者的开发效率,采用了类似使用了vue的代码书写风格,开发者可以熟练的上手小程序开发。

先上效果图

267

1:新建四个界面
在components
底下新建四个wepy文件
分别是
message 消息列表界面

  1. <template>
  2. <view class="me">
  3. 消息列表界面
  4. </view>
  5. </template>
  6. <script>
  7. import wepy from 'wepy';
  8. export default class Me extends wepy.component {
  9. components = {
  10. }
  11. methods = {
  12. };
  13. }
  14. </script>

contact联系人界面

  1. <template>
  2. <view class="me">
  3. 联系人界面
  4. </view>
  5. </template>
  6. <script>
  7. import wepy from 'wepy';
  8. export default class Me extends wepy.component {
  9. components = {
  10. }
  11. methods = {
  12. };
  13. }
  14. </script>

discovery发现界面

  1. <template>
  2. <view class="me">
  3. 发现界面
  4. </view>
  5. </template>
  6. <script>
  7. import wepy from 'wepy';
  8. export default class Me extends wepy.component {
  9. components = {
  10. }
  11. methods = {
  12. };
  13. }
  14. </script>

me我的主页

  1. <template>
  2. <view class="me">
  3. 我的主页
  4. </view>
  5. </template>
  6. <script>
  7. import wepy from 'wepy';
  8. export default class Me extends wepy.component {
  9. components = {
  10. }
  11. methods = {
  12. };
  13. }
  14. </script>

1000

2:编写index界面代码

  1. <style type="scss">
  2. .tab_item {
  3. height: 100%;
  4. }
  5. page, .body{
  6. height: 100%;
  7. font-family: '\5FAE\8F6F\96C5\9ED1', arial;
  8. background-color: #f0eff5;
  9. }
  10. </style>
  11. <template>
  12. <view class="body">
  13. <view class="tab_item tab_message" hidden="{
  14. {currentTab != 0}}">
  15. <message />
  16. </view>
  17. <view class="tab_item tab_contact" hidden="{
  18. {currentTab != 1}}">
  19. <contact />
  20. </view>
  21. <view class="tab_item tab_discovery" hidden="{
  22. {currentTab != 2}}">
  23. <discovery />
  24. </view>
  25. <view class="tab_item tab_me" hidden="{
  26. {currentTab != 3}}">
  27. <me />
  28. </view>
  29. <tab :active.sync="currentTab" />
  30. <toast />
  31. </view>
  32. </template>
  33. <script>
  34. import wepy from 'wepy';
  35. import Message from '../components/message';
  36. import Discovery from '../components/discovery';
  37. import Contact from '../components/contact';
  38. import Me from '../components/me';
  39. import Tab from '../components/tab';
  40. import Toast from 'wepy-com-toast';
  41. export default class Index extends wepy.page {
  42. config = {
  43. 'navigationBarTitleText': 'wepy - 微信',
  44. 'navigationBarTextStyle': 'white',
  45. 'navigationBarBackgroundColor': '#3b3a40'
  46. };
  47. components = {
  48. message: Message,
  49. discovery: Discovery,
  50. me: Me,
  51. contact: Contact,
  52. tab: Tab,
  53. toast: Toast
  54. };
  55. data = {
  56. currentTab: 0
  57. };
  58. methods = {
  59. };
  60. onShow() {
  61. this.currentTab = 0;
  62. this.$invoke('message', 'loadMessage');
  63. }
  64. showToast(name) {
  65. let promise = this.$invoke('toast', 'show', {
  66. title: `${name}`,
  67. img: 'https://raw.githubusercontent.com/kiinlam/wetoast/master/images/star.png'
  68. });
  69. promise.then((d) => {
  70. console.log('toast done');
  71. });
  72. }
  73. }
  74. </script>

1000 1

3:新建images文件夹,准备图标

263

4:在components底下新建tab.wpy
编写代码

  1. <style type="scss">
  2. $fontcolor: #7b7b7b;
  3. $activecolor: #13b113;
  4. .tab {
  5. color: $fontcolor;
  6. position: fixed;
  7. bottom: 0;
  8. height: 100rpx;
  9. width: 100%;
  10. border-top: 1px solid #dad9d6;
  11. background-color: #f7f7f7;
  12. font-size: 24rpx;
  13. white-space: nowrap;
  14. .tab_item {
  15. &.active {
  16. color: $activecolor;
  17. }
  18. display: inline-block;
  19. width: 25%;
  20. text-align: center;
  21. }
  22. .icon {
  23. width: 60rpx;
  24. height: 60rpx;
  25. display: block;
  26. margin: auto;
  27. }
  28. .title {
  29. padding-top: 6rpx;
  30. display: block;
  31. }
  32. }
  33. </style>
  34. <template>
  35. <view class="tab">
  36. <view class="tab_item tab_message{
  37. {active == 0 ? ' active' : ''}}" @tap="change(0)">
  38. <image class="icon" src="../images/message{
  39. {active == 0 ? '_active' : ''}}.png"></image>
  40. <text class="title">微信</text>
  41. </view>
  42. <view class="tab_item tab_contact{
  43. {active == 1 ? ' active' : ''}}" @tap="change(1)">
  44. <image class="icon" src="../images/contact{
  45. {active == 1 ? '_active' : ''}}.png"></image>
  46. <text class="title">通讯录</text>
  47. </view>
  48. <view class="tab_item tab_discovery{
  49. {active == 2 ? ' active' : ''}}" @tap="change(2)">
  50. <image class="icon" src="../images/discovery{
  51. {active == 2 ? '_active' : ''}}.png"></image>
  52. <text class="title">发现</text>
  53. </view>
  54. <view class="tab_item tab_me{
  55. {active == 3 ? ' active' : ''}}" @tap="change(3)">
  56. <image class="icon" src="../images/me{
  57. {active == 3 ? '_active' : ''}}.png"></image>
  58. <text class="title"></text>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. import wepy from 'wepy';
  64. export default class Tab extends wepy.component {
  65. props = {
  66. active: {
  67. twoWay: true
  68. }
  69. };
  70. data = {
  71. };
  72. methods = {
  73. change (idx, evt) {
  74. this.active = +idx;
  75. }
  76. };
  77. onLoad () {
  78. }
  79. }
  80. </script>

1000 2

5:一切准备就绪,编译

646

6:打开微信开发者工具,查看效果(开篇已经给出动态图效果)

1000 3

github:https://github.com/wangxiaoting666/wepy-myproject


原文作者:祈澈姑娘 技术博客:https://www.jianshu.com/u/05f416aefbe1
90后前端妹子,爱编程,爱运营,文艺与代码齐飞,魅力与智慧共存的程序媛一枚。

  • 关注「编程微刊」公众号 ,在微信后台回复「领取资源」,获取IT资源300G干货大全。

70

发表评论

表情:
评论列表 (有 0 条评论,462人围观)

还没有评论,来说两句吧...

相关阅读

    相关 底部导航

    1.添加相应的文件 2.分别加入4个Fragment以及布局文件 3.MianActivity的引用 4.MainActivity的布局文件   添加相应的文件:

    相关 导航切换效果

    在网页中经常会遇到导航栏切换效果,也就是鼠标放到某一导航栏上,底下对应的内容就会发生变化.下面说一下实现思路: 首先说下this的用法: this在事件中指向的是事件源对象