<view class="nav"> <view class="{{style[0]}}" data-id="{{0}}" bind:tap="clickFu">首页</view> <view class="{{style[1]}}" data-id="{{1}}" bind:tap="clickFu">关于我们</view> </view> <view hidden="{{show[0]}}">内容一</view> <view hidden="{{show[1]}}">内容二</view>
/ * * * Page initial data * / Data: { Show: [ to false , to true ], style: [ 'Active', '' ] }, / * navigation click * / clickFu (E) { // Get the Click ID-Data the let ID = e.currentTarget.dataset.id; // the this.data.show are changed to true the this .data.show.forEach ((Item, index) => { the this .data.show [index] = to true ; the this .data.style [index] = '' ; }); // click index is changed to false the this .data.show [ID] =false; this.data.style[id] = 'active'; this.setData({ show:this.data.show, style: this.data.style }) },