微信小程序 导航栏切换视图

效果图

.wxml页面

<!-- nav导航 -->

<view class="goods">

  <block wx:for="{{tab}}" wx:key="key">

    <view class="{{item.style}}" bindtap="tarClick" data-index="{{index}}">{{item.titcle}}</view>

  </block>

</view>

<!--导航下  视图滑块 -->

<swiper bind:change="changeTab" current="{{index}}">

   <block>

     <swiper-item>

     <text>11111</text>

     </swiper-item>

     <swiper-item>

     <text>2222</text>

     </swiper-item>

     <swiper-item>

     <text>3333</text>

     </swiper-item>

   </block>

</swiper>



.js页面

Page({

    data: {

       tab:[

         {titcle:"商品参数",style:"color"}, 

         {titcle:"商品介绍",style:""},

         {titcle:"商品规格",style:""},

        ],

        index:0,

       goods:''

    },

       tarClick(e){

          //  console.log(e.currentTarget.dataset.index)

           let tab = this.data.tab;

          let that = this;

          let index = e.currentTarget.dataset.index

           console.log(index)

          tab.map((item,key)=>{

           if(key==index)

           {

              tab[key]['style']='color';

           }else{

             tab[key]['style']='';

           }

          })

          that.setData({tab,index})


       },changeTab(e){

          console.log(e.detail.current)

          let tab = this.data.tab;

          let that = this;

          let index = e.detail.current

           console.log(index)

          tab.map((item,key)=>{

           if(key==index)

           {

              tab[key]['style']='color';

           }else{

             tab[key]['style']='';

           }

          })

          that.setData({tab,index})

       },

})



.wxss页面

/* pages/details/details.wxss */


.goods{

    width: 100%;

    height: 100rpx;

    /* background-color:yellowgreen; */

    display:flex;

    justify-content: space-around;

    align-items: center;

}

.goods view{

    width: 160rpx;

    height: 100rpx;

    display: flex;

    justify-content: center;

    align-items: center;


}

.color{

    color: red;

    border-bottom: 2px solid red;

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 实现该功能的思路:通过点击左侧滑栏的某一项,获取到该元素携带的 id ,然后动态传给右侧滑栏的 scroll-in...
    _vb阅读 777评论 0 1
  • 一、创建项目 1、准备工作 微信公众平台注册开发者账号:https://mp.weixin.qq.com/[htt...
    一个想读书的人阅读 1,508评论 0 1
  • 微信小程序 一、创建项目 1、准备工作 微信公众平台注册开发者账号:https://mp.weixin.qq.co...
    名字真难取啊阅读 713评论 0 0
  • 一:小程序云开发的基本页面结构 1.cloudfunctions是指定腾讯云开发的项目目录 2.miniprogr...
    jjbnxy阅读 3,823评论 0 2
  • 微信小程序 一、创建项目 1、准备工作 微信公众平台注册开发者账号:https://mp.weixin.qq.co...
    元肖阅读 1,241评论 0 2

友情链接更多精彩内容