1月9號(hào)微信小程序正是上線(xiàn),在網(wǎng)上嘗試了一下,發(fā)現(xiàn)很厲害。所以研究了一下。
下面是我的demo:
包含四個(gè)頁(yè)面:news.js/news.wxss/news.json/news.wxml
1.news.wxml:
<scroll-view class="news_banner">
<view wx:for="{{selections}}" wx:for-index="idx" data-idx="{{idx}}" class="news_banner_text {{item.show?'select':''}}" data-cid="{{item.cateid}}" bindtap="bannerClick" >
<text>{{item.catename}}</text>
</view>
</scroll-view>
<view class="news">
<view wx:for="{{newsList}}" class="news_list" data-nid="{{item.NewsId}}" data-ntitle="{{item.Title}}" data-nimg="{{item.Pic}}" data-nsource="{{item.Source}}" bindtap="newsClick">
<view class="news_left">
<image mode="scaleToFill" src="http://static.iyuba.com/cms/news/image/{{item.Pic}}"></image>
<text class="news_date">{{item.CreatTime}}</text>
</view>
<view class="news_right">
<text class="news_title news_text">{{item.Title}}</text>
<text class="news_subTitle news_text">{{item.Title_cn}}({{item.WordCount}} words)</text>
<view class="news_data">
<text>難度:{{item.HardWeight}}|</text>
<text>閱讀:{{item.ReadCount}}|</text>
<text>{{item.UserName}}|</text>
<text>來(lái)源:{{item.Source}}</text>
</view>
</view>
</view>
</view>
2.news.js
var app = getApp();
var TimeUtil = require('../../utils/util.js');
var bannerList = [
{'cateid':12134,'catename':'職場(chǎng)','show':false},
{'cateid':12235,'catename':'政治','show':false},
{'cateid':122316,'catename':'經(jīng)濟(jì)','show':false},
{'cateid':112317,'catename':'文化','show':false},
{'cateid':123228,'catename':'生活','show':false},
]
Page({
data : {
},
onLoad: function(options){
this.setData({
maxId : 0,
cateid : 0,
selections : bannerList
})
this.loadNews(0);
},
onReady:function(){
},
onShow:function(){
},
onHide:function(){
},
onUnload:function(){
},
onPullDownRefresh: function() {
this.setData({
maxId : 0
});
下拉加載新聞
this.loadNews(0);
},
onReachBottom: function() {
this.loadNews(2)
},
bannerClick: function(e){
4.效果
微信web開(kāi)發(fā)工具,用起來(lái)有點(diǎn)坑,所以選擇的是其他的編輯器,然后用微信web開(kāi)發(fā)工具編譯。另外界面并不美觀(guān),畢竟不是為了好看。