微信小程序wepy框架入门教程-底部导航栏效果(五)

简介: 微信小程序wepy框架入门教程-底部导航栏效果(五)

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

先上效果图

1:新建四个界面

在components

底下新建四个wepy文件

分别是

message 消息列表界面

<template>
  <view class="me">
   消息列表界面
  </view>
</template>
<script>
  import wepy from 'wepy';
  export default class Me extends wepy.component {
    components = {
    }
    methods = {
    };
  }
</script>

contact联系人界面

<template>
  <view class="me">
    联系人界面
  </view>
</template>
<script>
  import wepy from 'wepy';
  export default class Me extends wepy.component {
    components = {
    }
    methods = {
    };
  }
</script>

discovery发现界面

<template>
  <view class="me">
   发现界面
  </view>
</template>
<script>
  import wepy from 'wepy';
  export default class Me extends wepy.component {
    components = {
    }
    methods = {
    };
  }
</script>

me我的主页

<template>
  <view class="me">
   我的主页
  </view>
</template>
<script>
  import wepy from 'wepy';
  export default class Me extends wepy.component {
    components = {
    }
    methods = {
    };
  }
</script>

2:编写index界面代码

<style type="scss">
  .tab_item {
    height: 100%;
  }
  page, .body{
    height: 100%;
    font-family: '\5FAE\8F6F\96C5\9ED1', arial;
    background-color: #f0eff5;
  }
</style>
<template>
  <view class="body">
    <view class="tab_item tab_message" hidden="{{currentTab != 0}}">
      <message />
    </view>
    <view class="tab_item tab_contact" hidden="{{currentTab != 1}}">
      <contact />
    </view>
    <view class="tab_item tab_discovery" hidden="{{currentTab != 2}}">
      <discovery />
    </view>
    <view class="tab_item tab_me" hidden="{{currentTab != 3}}">
      <me />
    </view>
    <tab :active.sync="currentTab" />
    <toast />
  </view>
</template>
<script>
  import wepy from 'wepy';
  import Message from '../components/message';
  import Discovery from '../components/discovery';
  import Contact from '../components/contact';
  import Me from '../components/me';
  import Tab from '../components/tab';
  import Toast from 'wepy-com-toast';
  export default class Index extends wepy.page {
    config = {
      'navigationBarTitleText': 'wepy - 微信',
      'navigationBarTextStyle': 'white',
      'navigationBarBackgroundColor': '#3b3a40'
    };
    components = {
      message: Message,
      discovery: Discovery,
      me: Me,
      contact: Contact,
      tab: Tab,
      toast: Toast
    };
    data = {
      currentTab: 0
    };
    methods = {
    };
    onShow() {
      this.currentTab = 0;
      this.$invoke('message', 'loadMessage');
    }
    showToast(name) {
      let promise = this.$invoke('toast', 'show', {
        title: `${name}`,
        img: 'https://raw.githubusercontent.com/kiinlam/wetoast/master/images/star.png'
      });
      promise.then((d) => {
        console.log('toast done');
      });
    }
  }
</script>


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

4:在components底下新建tab.wpy

编写代码

<style type="scss">
  $fontcolor: #7b7b7b;
  $activecolor: #13b113;
  .tab {
    color: $fontcolor;
    position: fixed;
    bottom: 0;
    height: 100rpx;
    width: 100%;
    border-top: 1px solid #dad9d6;
    background-color: #f7f7f7;
    font-size: 24rpx;
    white-space: nowrap;
    .tab_item {
      &.active {
        color: $activecolor;
      }
      display: inline-block;
      width: 25%;
      text-align: center;
    }
    .icon {
      width: 60rpx;
      height: 60rpx;
      display: block;
      margin: auto;
    }
    .title {
      padding-top: 6rpx;
      display: block;
    }
  }
</style>
<template>
  <view class="tab">
    <view class="tab_item tab_message{{active == 0 ? ' active' : ''}}" @tap="change(0)">
      <image class="icon" src="../images/message{{active == 0 ? '_active' : ''}}.png"></image>
      <text class="title">微信</text>
    </view>
    <view class="tab_item tab_contact{{active == 1 ? ' active' : ''}}" @tap="change(1)">
      <image class="icon" src="../images/contact{{active == 1 ? '_active' : ''}}.png"></image>
      <text class="title">通讯录</text>
    </view>
    <view class="tab_item tab_discovery{{active == 2 ? ' active' : ''}}" @tap="change(2)">
      <image class="icon" src="../images/discovery{{active == 2 ? '_active' : ''}}.png"></image>
      <text class="title">发现</text>
    </view>
    <view class="tab_item tab_me{{active == 3 ? ' active' : ''}}" @tap="change(3)">
      <image class="icon" src="../images/me{{active == 3 ? '_active' : ''}}.png"></image>
      <text class="title">我</text>
    </view>
  </view>
</template>
<script>
  import wepy from 'wepy';
  export default class Tab extends wepy.component {
    props = {
      active: {
        twoWay: true
      }
    };
    data = {
    };
    methods = {
      change (idx, evt) {
        this.active = +idx;
      }
    };
    onLoad () {
    }
  }
</script>

5:一切准备就绪,编译

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

相关文章
|
2月前
|
小程序 前端开发 数据可视化
微信小程序云开发入门教程-全局文件介绍
微信小程序云开发入门教程-全局文件介绍
|
2月前
|
小程序 前端开发 程序员
微信小程序开发入门教程-小程序账号注册及开通
微信小程序开发入门教程-小程序账号注册及开通
|
2月前
|
小程序 JavaScript
在使用微信小程序开发中用vant2框架中的Uploader 文件上传wx.uploadFile无反应和使用多图上传
网上有的说是bind:after-read="afterRead"的命名问题不支持-,但是我这儿执行了console.log("file",file);证明函数运行了。后来发现是multiple="true"原因开启了多图上传,如果是多图上传的话file就是数组了
45 2
|
2月前
|
小程序 前端开发 JavaScript
微信小程序MINA框架
微信小程序MINA框架
62 0
|
2月前
|
小程序 前端开发 开发者
TDesign电商小程序模板解析01-自定义底部导航栏
TDesign电商小程序模板解析01-自定义底部导航栏
|
2月前
|
小程序 数据可视化 前端开发
微信小程序开发入门教程-文本组件介绍
微信小程序开发入门教程-文本组件介绍
|
2月前
|
存储 小程序 数据库
微信小程序云开发入门教程-服务开通
微信小程序云开发入门教程-服务开通
|
3月前
|
JSON 小程序 数据格式
|
18天前
|
小程序 前端开发 API
小程序全栈开发中的多端适配与响应式布局
【4月更文挑战第12天】本文探讨了小程序全栈开发中的多端适配与响应式布局。多端适配涉及平台和设备适应,确保统一用户体验;响应式布局利用媒体查询和弹性布局维持不同设备的布局一致性。实践中,开发者可借助跨平台框架实现多平台开发,运用响应式布局技术适应不同设备。同时,注意兼容性、性能优化和用户体验,以提升小程序质量和用户体验。通过这些方法,开发者能更好地掌握小程序全栈开发。
|
18天前
|
小程序 前端开发 API
微信小程序全栈开发中的异常处理与日志记录
【4月更文挑战第12天】本文探讨了微信小程序全栈开发中的异常处理和日志记录,强调其对确保应用稳定性和用户体验的重要性。异常处理涵盖前端(网络、页面跳转、用户输入、逻辑异常)和后端(数据库、API、业务逻辑)方面;日志记录则关注关键操作和异常情况的追踪。实践中,前端可利用try-catch处理异常,后端借助日志框架记录异常,同时采用集中式日志管理工具提升分析效率。开发者应注意安全性、性能和团队协作,以优化异常处理与日志记录流程。