由於微信小程序開發不同於以往的普通web開發, 因此無法通過js獲取wxml文件的dom結構, 因此從js上直接添加一個類名應該不可能了. 可是我們可以通過微信小程序數據綁定以及view標簽的”data-“自定義屬性去更改標簽類名.


num記得設置默認值 ,這樣第一個view顏色會是紅色的
data:{
num:0,
}
.cur寫上樣式
.cur{ border-bottom: 4rpx solid #f23232; color: #f23232; }
switchTab:function(e){ let id=e.currentTarget.dataset.id, index=parseInt(e.currentTarget.dataset.index), num=parseInt(e.currentTarget.dataset.index) this.curIndex=parseInt(e.currentTarget.dataset.index) console.log(e) var that=this this.setData({ curNavId:id, curIndex:index, num:index }) },
參考自:http://blog.csdn.net/c_kite/article/details/72899520
