弄了半天,都比较难以实现类似随笔博客首页菜单切换的样式,因为不知道js中如何获取标签,然后只能用数据绑定的方式来解决,如下代码,当然只是一个凌乱的例子:
1、sb.wxml
<!--pages/sb/sb.wxml--><view class="top"><view class="tops {{new==1?'choice':'nochoice'}}" bindtap="getNewTopics"><text>最新</text></view><view class="top_span tops"></view><view class="tops {{month==1?'choice':'nochoice'}}" bindtap="getMonthTopics"><text>月榜</text></view><view class="top_span tops"></view><view class="tops {{year==1?'choice':'nochoice'}}" bindtap="getYearTopics"><text>年榜</text></view><view class="top_span tops"></view><view class="tops {{user==1?'choice':'nochoice'}}" bindtap="getHotUsers"><text>博主</text></view><view class="top_span tops"></view><view class="tops {{menu==1?'choice':'nochoice'}}" bindtap="getHotMenus"><text>标签</text></view></view>
2、sb.wxss
/* pages/sb/sb.wxss */.top{font-size: 14px;width: 100%;text-align: center;}.tops{display: inline-block;color: #231815;padding-bottom: 3px;}.top_span{margin-left: 5px;margin-right: 5px;width: 0px;}.choice {color: #231815;border-bottom: 1px solid #333;padding-bottom: 2px;}.nochoice {color: #A3A3A3;border-bottom: 0px solid #333;}
3、sb.js
// pages/sb/sb.jsPage({data: {motto: 'Hello World',new: 1},//事件处理函数getNewTopics: function () {this.setData({new: 1,month:0,year:0,user:0,menu:0});// wx.request({// url: "https://www.suibibk.com/getTopics",// data: {menuid:0,userid:0,page:1,hot:"",type:0},// method:"POST",// header: {// "Content-Type":"application/json"// },// success: function (res) {// console.log(res.data)// },// fail: function (err) {// console.log(err)// }// })},//事件处理函数getMonthTopics: function () {this.setData({new: 0,month: 1,year: 0,user: 0,menu: 0});},//事件处理函数getYearTopics: function () {this.setData({new: 0,month: 0,year: 1,user: 0,menu: 0});},//事件处理函数getHotUsers: function () {this.setData({new: 0,month: 0,year: 0,user: 1,menu: 0});},//事件处理函数getHotMenus: function () {this.setData({new: 0,month: 0,year: 0,user: 0,menu: 1});}})
4、sb.json
{"navigationBarTitleText": "随笔小博客","component": true,"usingComponents": {}}
5、运行实例,如下呈现

总结
不知道啥时候可以开启小程序的学习。
