关于小程序自定义标题-商品详情

最近因为大环境的影响,公司决定做小程序来应对市场的变化。所以我也来学习小程序开发,而且希望培养自己记录问题的习惯。今天就来记录下自定义标题。

一、首先找到你的页面的json文件

在这通常是设置标题,和引用组件的。现在加上:"navigationStyle":"custom",去掉小程序自带的头部和返回键,但是会保留右上角的胶囊。现在可以自定义头部了。

{
  "usingComponents": {},
  "navigationStyle":"custom"
}

先给大家看下效果图:


自定义标题栏.jpg

wxml代码:

<view class="Header" style="padding-top:{{statusBarHeight}}px">
  <image class="back" src="/assets/images/ic_back.png" bindtap="backClick"/>
  <view class="Info">
    <view class="title" data-type="0" bindtap="titleChangeClick">
      <text class="titleText">商品</text>
      <view hidden="{{currentTab==0?false:true}}" class="bottom"></view>
    </view>
    <view class="title" data-type="1" bindtap="titleChangeClick">
      <text class="titleText">评价</text>
      <view hidden="{{currentTab==1?false:true}}" class="bottom"></view>
    </view>
    <view class="title" data-type="2" bindtap="titleChangeClick">
      <text class="titleText">详情</text>
      <view hidden="{{currentTab==2?false:true}}" class="bottom"></view>
    </view>
  </view>
  <image class="back" />
</view>

wxss代码:

.Header {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  background-color: #3878f4;
  height: 45px;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
}

.Info {
  flex: 1;
  height: 100%;
  display: flex;
  justify-content: center;
}
.title{
  position: relative;
  display: flex;
  align-items: center;
  margin: 5rpx;
}
.back {
  width: 55rpx;
  height: 53rpx;
  margin: 10rpx;
}
.titleText {
  color: white;
  size: 26rpx;
}
.bottom {
  position: absolute;
  bottom: 0;
  background-color: white;
  height: 5rpx;
  width: 100%;
}

js代码

const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    currentTab:{
      type: Number,
      value:0
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    statusBarHeight: app.globalData.statusBarHeight,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    titleChangeClick(e){//标题切换
      var currentTab = e.currentTarget.dataset.type;
      this.setData({
        currentTab
      })
      this.triggerEvent('changeTitle', {
        currentTab: currentTab
      })
    },
    backClick(e){
      wx.navigateBack({});
    }
  }
})
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 因新工作主要负责微信小程序这一块,最近的重心就移到这一块,该博客是对微信小程序整体的整理归纳以及标明一些细节点,初...
    majun00阅读 7,639评论 0 9
  • 1.小程序起步 (1)点击https://mp.weixin.qq.com/wxopen/waregister?a...
    GXW_Lyon阅读 3,604评论 0 0
  • 微信小程序的特点 小程序是一种不需要下载、安装即可使用的应用,它出现了触手可及的梦想,用户扫一扫或者搜一下即开打开...
    Simple_3f19阅读 971评论 0 0
  • 每天的学习记录,可能有的地方写的不对,因为刚学,以后发现错的话会回来改掉整体流程 https://develope...
    有点健忘阅读 5,035评论 0 7
  • 配置文件 app.json的配置(全局) { // 用来配置页面的路径 "pages":[ "pages/inde...
    左狐偃阅读 647评论 0 0

友情链接更多精彩内容