微信小程序 導航欄切換視圖

效果圖

.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:"商品參數(shù)",style:"color"},?

?????????{titcle:"商品介紹",style:""},

?????????{titcle:"商品規(guī)格",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;

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 實現(xiàn)該功能的思路:通過點擊左側(cè)滑欄的某一項,獲取到該元素攜帶的 id ,然后動態(tài)傳給右側(cè)滑欄的 scroll-in...
    _vb閱讀 776評論 0 1
  • 一、創(chuàng)建項目 1、準備工作 微信公眾平臺注冊開發(fā)者賬號:https://mp.weixin.qq.com/[htt...
    一個想讀書的人閱讀 1,497評論 0 1
  • 微信小程序 一、創(chuàng)建項目 1、準備工作 微信公眾平臺注冊開發(fā)者賬號:https://mp.weixin.qq.co...
    名字真難取啊閱讀 712評論 0 0
  • 一:小程序云開發(fā)的基本頁面結(jié)構(gòu) 1.cloudfunctions是指定騰訊云開發(fā)的項目目錄 2.miniprogr...
    jjbnxy閱讀 3,815評論 0 2
  • 微信小程序 一、創(chuàng)建項目 1、準備工作 微信公眾平臺注冊開發(fā)者賬號:https://mp.weixin.qq.co...
    元肖閱讀 1,235評論 0 2

友情鏈接更多精彩內(nèi)容