微信小程序实现选项卡的简单实例

本文实例为大家分享了微信小程序实现选项卡的具体代码,供大家参考,具体内容如下

效果图

实现的功能:点击上面选项卡,下面商品内容实现切换,滑动下面的商品页面,上面的选项也随页面进行切换。

text.wxml:

<!-- 分类 -->
<view class='listMiddle swiper-tab'>
  <view class='middle {{currentTab==0? "action" : ""}}' data-current="0" bindtap="clickTab">
    全部
  </view>
  <view class='middle {{currentTab==1? "action":""}}' data-current="1" bindtap="clickTab">
    分类1
  </view>
  <view class='middle {{currentTab==2? "action":""}}' data-current="2" bindtap="clickTab">
    分类2
  </view>
  <view class='middle {{currentTab==3? "action":""}}' data-current="3" bindtap="clickTab">
    分类3
  </view>
</view>
<!-- 精选商品 -->
<swiper current="{{currentTab}}" duration="300" bindchange="swiperTab" >
//注意这里只是写了循环出来一条数据,要实现多条数据,要学会用数据嵌套循环哦~~
  <swiper-item wx:for="{{jingxuan}}">
    <view class='loopmiddle'>
      <view class='lo-left'>
        <image src='{{item.hua}}'></image>
      </view>
      <view class='lo-middle'>
        <view>{{item.guo}}</view>
        <view>{{item.zhigong}}</view>
        <view class='loo-bottom'>
          <text>{{item.qi}}</text>
          <image src='{{item.huo}}'></image>
          <text>{{item.fen}}</text>
        </view>
      </view>
      <view class='lo-right'>
        <image src='{{item.xiaoche}}'></image>
      </view>
    </view>
  </swiper-item>
</swiper>

test.js

var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    jingxuan: [{
      hua: "../../assets/hua.png", guo: "9.9元1斤惊爆价 - A级千禧圣女果", zhigong: "产地直供,一箱约8斤", qi: "¥71.90", huo: "../../assets/huomiao.png", fen: "已购999份", xiaoche: "../../assets/xiaoche.png", },
      {
      hua: "../../assets/hua.png", guo: "9.9元1斤惊爆价 - A级千禧圣女果", zhigong: "产地直供,一箱约8斤", qi: "¥72.90", huo: "../../assets/huomiao.png", fen: "已购999份", xiaoche: "../../assets/xiaoche.png", },
      {
      hua: "../../assets/hua.png", guo: "9.9元1斤惊爆价 - A级千禧圣女果", zhigong: "产地直供,一箱约8斤", qi: "¥73.90", huo: "../../assets/huomiao.png", fen: "已购999份", xiaoche: "../../assets/xiaoche.png", },
      {
      hua: "../../assets/hua.png", guo: "9.9元1斤惊爆价 - A级千禧圣女果", zhigong: "产地直供,一箱约8斤", qi: "¥74.90", huo: "../../assets/huomiao.png", fen: "已购999份", xiaoche: "../../assets/xiaoche.png", },
    ],
    currentTab: 0,
  },

  //滑动切换
  swiperTab: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
      
    });
    console.log(e.detail.current)
  },
  //点击切换
  clickTab: function (e) {

    var that = this;

    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  } ,

text.wxss

/* 分类 */
.listMiddle{
  display: flex;
  font-size: 40rpx;
  border-bottom: 1px solid #ebebeb;
  height: 90rpx;
  line-height: 90rpx;
 
}
.middle{
   margin-left: 60rpx; 
   height: 90rpx;
   width: 120rpx;

}

.action{
  height: 90rpx;
  width: 120rpx;
  color: #3ad965;
  border-bottom:2px solid #3ad965;
}
/* 精选商品开始 */
.loopmiddle{
   width: 690rpx;
  margin: 5rpx auto 0;
  /* overflow: hidden; */
  display: flex;
  margin-bottom: 40rpx;
  border-bottom: 1rpx solid #eff0f4;
}

.lo-left{
  /* float: left; */
  height: 250rpx;
  width: 250rpx;
}
.lo-left image{
  height: 250rpx;
  width: 250rpx;
}
.lo-middle{
  margin-top:40rpx;
}
.lo-middle view:nth-child(1){
  font-size:25rpx;
  color:#676767;
  margin-left: 10rpx;

}
.lo-middle view:nth-child(2){
  font-size:20rpx;
  color:#adadad;
  margin-top:20rpx;
  margin-left: 10rpx;

}
.loo-bottom{
  margin-top: 40rpx;
}
.loo-bottom text:nth-child(1){
  margin-right: 15rpx;
  font-size:40rpx;
  color:#fe6400;

}
.loo-bottom text:last-child{
  font-size:20rpx;
  color:#4b3333;

}
.loo-bottom image{
  width: 35rpx;
  height: 35rpx;
  vertical-align: middle;
}
.lo-right{
  width: 50rpx;
  height: 50rpx;
}
.lo-right image{
   width: 50rpx;
  height: 50rpx;
}
.lo-right{
  margin-top:170rpx;
}
.active{
  color:aqua;
  border-bottom: 4rpx solid red;
}
.swiper-tab{
  width: 100%;
  border-bottom: 2rpx solid #ccc;
  text-align: center;
  height: 88rpx;
  line-height: 88rpx;
  font-weight: bold;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • 微信小程序实现顶部选项卡(swiper)

    微信小程序顶部选项卡在开发中是非常常用的,下面用一点时间实现了一下. 效果图: 下面直接上代码: wxml: <!--pages/index/index.wxml--> <view class="swiper-tab"> <view class="tab-item {{currentTab==0 ? 'on' : ''}}" data-current="0" bindtap="swichNav"&

  • 微信小程序的tab选项卡的实现效果

    效果图,既可以点击切换,又可以滑动切换 .wxml <!--pages/detail/detail.wxml--> <view class="swiper-tab"> <view class="swiper-tab-item {{currentTab==0?'active':''}}" data-current="0" bindtap="clickTab">全部</view> &

  • 微信小程序自定义组件实现tabs选项卡功能

    本文为大家分享了微信小程序实现tabs选项卡功能的具体代码,供大家参考,具体内容如下 一个自定义组件由 json wxml wxss js 4个文件组成.要编写一个自定义组件,首先需要在 json 文件中进行自定义组件声明(将 component 字段设为 true 可这一组文件设为自定义组件) components/navigator/index.json { "component": true } components/navigator/index.wxml <!-- 自定

  • 微信小程序实现选项卡的方法

    本文实例为大家分享了微信小程序实现选项卡的具体代码,供大家参考,具体内容如下 微信小程序里没有自带选项卡组件,但是却带有swiper组件,所以,我们便利用swiper来实现选项卡的功能. 先看效果图: test.wxml <view class="swiper-tab">   <view class="swiper-tab-item {{currentTab==0?'active':''}}" data-current="0"

  • 微信小程序开发之实现选项卡(窗口顶部TabBar)页面切换

    微信小程序开发中选项卡.在Android中选项卡一般用fragment,到了小程序这里瞬间懵逼了. 总算做出来了.分享出来看看. 先看效果: 再上代码: 1.index.wxml <!--index.wxml--> <view class="swiper-tab"> <view class="swiper-tab-list {{currentTab==0 ? 'on' : ''}}" data-current="0"

  • 微信小程序 tabs选项卡效果的实现

    微信小程序 tabs选项卡效果 前言: 最近微信应用号是炒的如火如荼,热门满满,但是也可以发现搜索关键词出来,各类网站出现的还都是微信的官方文档解释.正好赶上这个热潮,这几天先把小程序技术文档看了个遍,就直接着手写案例了.很多组件微信内部已经封装完了,正好发现没有tab选项卡效果,这两天正好研究了下.思路如下: 1.首先点击导航的时候需要两个变量,一个存储当前点击样式类,一个是其它导航默认的样式类 2.选项卡内容列表同样也需要两个变量,一个存储当前显示块,一个存储的是其它隐藏的默认块 3.使用三

  • 微信小程序开发之选项卡(窗口底部TabBar)页面切换

    微信小程序开发中窗口底部tab栏切换页面很简单很方便. 代码: 1.app.json //app.json { "pages":[ "pages/index/index", "pages/logs/logs" ], "window":{ "backgroundTextStyle":"light", "navigationBarBackgroundColor": &qu

  • 微信小程序实现选项卡功能

    本文实例为大家分享了微信小程序选项卡功能展示的具体代码,供大家参考,具体内容如下 首先看看微信小程序上的选项卡的效果: 原理呢,就是先布局好(这就不必说了吧),然后在上面的每一个选项卡上都定义一个同样的点击事件,然后给每一个组件上绑定一个唯一的标识符,然后点击事件触发的时候,获取到绑定的标识符,判断当前点击的是哪个选项卡,然后再判断下面该显示哪一块,现在上代码: wxml: <view class="menu_box"> <text class='menu1 {{me

  • 微信小程序实战之顶部导航栏(选项卡)(1)

    本文实例为大家分享了微信小程序顶部导航栏的具体代码,供大家参考,具体内容如下 需求:顶部导航栏 效果图: wxml: <!--导航条--> <view class="navbar"> <text wx:for="{{navbar}}" data-idx="{{index}}" class="item {{currentTab==index ? 'active' : ''}}" wx:key=&qu

  • 微信小程序 选项卡的简单实例

    微信小程序 选项卡的简单实例 看下效果 代码: home.wxml <!--pages/home/home.wxml--> <view class="swiper-tab"> <view class="swiper-tab-item {{currentTab==0 ? 'on' : ''}}" data-current="0" bindtap="swichNav">热门</view&g

随机推荐