溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

微信小程序?qū)崿F(xiàn)選項卡的代碼怎么寫

發(fā)布時間:2022-07-19 09:46:55 來源:億速云 閱讀:159 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要介紹“微信小程序?qū)崿F(xiàn)選項卡的代碼怎么寫”的相關(guān)知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“微信小程序?qū)崿F(xiàn)選項卡的代碼怎么寫”文章能幫助大家解決問題。

效果圖

微信小程序?qū)崿F(xiàn)選項卡的代碼怎么寫

實現(xiàn)的功能:點擊上面選項卡,下面商品內(nèi)容實現(xiàn)切換,滑動下面的商品頁面,上面的選項也隨頁面進行切換。

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" >
//注意這里只是寫了循環(huán)出來一條數(shù)據(jù),要實現(xiàn)多條數(shù)據(jù),要學(xué)會用數(shù)據(jù)嵌套循環(huán)哦~~
  <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({

  /**
   * 頁面的初始數(shù)據(jù)
   */
  data: {
    jingxuan: [{
      hua: "../../assets/hua.png", guo: "9.9元1斤驚爆價 - A級千禧圣女果", zhigong: "產(chǎn)地直供,一箱約8斤", qi: "¥71.90", huo: "../../assets/huomiao.png", fen: "已購999份", xiaoche: "../../assets/xiaoche.png", },
      {
      hua: "../../assets/hua.png", guo: "9.9元1斤驚爆價 - A級千禧圣女果", zhigong: "產(chǎn)地直供,一箱約8斤", qi: "¥72.90", huo: "../../assets/huomiao.png", fen: "已購999份", xiaoche: "../../assets/xiaoche.png", },
      {
      hua: "../../assets/hua.png", guo: "9.9元1斤驚爆價 - A級千禧圣女果", zhigong: "產(chǎn)地直供,一箱約8斤", qi: "¥73.90", huo: "../../assets/huomiao.png", fen: "已購999份", xiaoche: "../../assets/xiaoche.png", },
      {
      hua: "../../assets/hua.png", guo: "9.9元1斤驚爆價 - A級千禧圣女果", zhigong: "產(chǎn)地直供,一箱約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;
}

關(guān)于“微信小程序?qū)崿F(xiàn)選項卡的代碼怎么寫”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識,可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點。

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI