微信小程序自定义顶部以及底部tabbar

本文介绍如何在微信小程序中创建自定义的顶部和底部Tabbar。通过建立模板,绘制WXML结构,编写WXSS样式,定义app.js中的参数和方法,以及在各页面中引入并接收数据,完成自定义组件。然而,存在一个问题:在下拉刷新时,顶部也会随之下拉加载,期待解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.首先建立一个模板,在里边模板的wxml里绘制公共的顶部以及底部
代码如下:

<!--pages/template/template.wxml-->
<template name="top">
<!-- 顶部 -->
   <view style="padding-top:{
  
  {topcontent.statusBarHeight+topcontent.titleBarHeight}}px;">
  <view class="hh-header" style='background-color:{
  
  {topcontent.background}};color:{
  
  {topcontent.color}};'>
    <view class="status-bar" style="height:{
  
  {topcontent.statusBarHeight}}px"></view>
    <view class="title-bar" style="height:{
  
  {topcontent.titleBarHeight}}px">
      <view wx:if="{
  
  {topcontent.isShowBack}}" class='hh-nav-back ico-back' bindtap='goback'></view>
      <view wx:if="{
  
  {!topcontent.isShowBack}}" class='hh-nav-back'></view>
      <view class="hh-title">{
  
  {topcontent.name}}</view>
      <view class="hh-nav-right"></view>
    </view>
  </view>
</view>
</template>
<!-- 底部 -->
<template name="tabbar">
    <view class="tabbar_box" style="background-color:{
  
  {tabbar.backgroundColor}}; border-top-color:{
  
  {tabbar.borderStyle}}; {
  
  {tabbar.position == 'top' ? 'top:0' : 'bottom:0'}}">
        <block wx:for="{
  
  {tabbar.list}}" wx:for-item="item" wx:key="index">
            <view class="tabbar_nav" style="width:{
  
  {1/tabbar.list.length*100}}%; " bindtap='switchTab' data-url='{
  
  {item.pagePath}}'>
                <image class="tabbar_icon" src="{
  
  {item.selected ? item.selectedIconPath : item.iconPath}}"></image>
                <text style="color:{
  
  {item.selected ? tabbar.selectedColor : tabbar.color}}">{
  
  {item.text}}</text>
            </view>
        </block>
    </view>
</template>

2.然后在模板的wxss里样式

 /* pages/template/template.wxss */
.tabbar_box{
    display: flex;
    flex-direction: row;
    justify-content: space-around;
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值