微信小程序仿貓眼電影的實現教程
movie.js
- Page({
- data: {
- movies:null,
- scrollTop : 0,
- scrollHeight:0
- },
- onLoad: function (options) {
- // 生命周期函數--監聽頁面加載
- // 這里要非常注意,微信的scroll-view必須要設置高度才能監聽滾動事件,所以,需要在頁面的onLoad事件中給scroll-view的高度賦值
- var that = this;
- wx.getSystemInfo({
- success:function(res){
- console.info(res.windowHeight);
- that.setData({
- scrollHeight:res.windowHeight
- });
- }
- });
- that.getAllMovies();
- },
- getAllMovies() {
- let thispage=this;
- //展示 加載框
- wx.showToast({
- title: '加載中',
- icon: 'loading',
- duration: 10000
- })
- //網絡請求數據
- wx.request({
- url: 'https://m.maoyan.com/movie/list.json?type=hot&offset=0&limit=1000',
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {'content-type':'json'}, // 設置請求的 header
- success: function(res){
- // success
- let obj=res.data.data.movies;
- //將獲取到的數據設置到 page 中的movies上
- thispage.setData({movies:obj});
- //隱藏加載框
- wx.hideToast();
- //停止刷新
- wx.stopPullDownRefresh();
- },
- fail: function() {
- // fail
- },
- complete: function() {
- // complete
- }
- })
- },
- //點擊事件
- itemClick(event){
- },
- //刷新
- onPullDownRefresh: function () {
- this.getAllMovies();
- },
- })
movie.json
- {
- "enablePullDownRefresh": true
- }
movie.wxml
- <view class="top">
- <text class="top_text">深圳</text>
- <view class="top_input">
- <input placeholder="Q找影視劇、找影院" />
- </view>
- </view>
- <view class="item" wx:for="{{movies}}" wx:key="{{index}}" bindtap="itemClick" hover-class="item_press" hover="true" >
- <view class="pic">
- <image src="{{item.img}}"></image>
- </view>
- <view class="detail">
- <title>{{item.nm}}
新聞熱點
疑難解答