获取更多电影

2019-06-05  本文已影响0人  授之以渔不如授之以鱼

moremovie.js获取movies.js传递过来的类名category,根据category跳转对应的case,加载对应的电影。

var util = require('../../../utils/util.js');
Page({
  data: {
    categoryTitle: "",
  },
  onLoad: function(options) {
    var dataUrl = ""
    var category = options.category;
    this.data.categoryTitle = category
    console.log(category, "category")
    switch (category) {
      case "正在热映":
        var dataUrl = app.globalData.doubanBase + 'v2/movie/in_theaters';
        break;
      case "即将上映":
        var dataUrl = app.globalData.doubanBase + 'v2/movie/coming_soon';
        break;
      case "top250":
        var dataUrl = app.globalData.doubanBase + 'v2/movie/top250';
        break;
    }
    util.http(dataUrl, this.callBack)
  },
  callBack: function(data) {
      console.log(data)
    },

util.js

function http(url,callBack) {
  wx.request({
    url: url,
    method: 'GET',
    header: {
      "content-Type": ""
    },
    success: function(res) {
      console.log(res)
      callBack(res.data);
    },
    fail: function(error) {
      console.log(error)
    }
  })
}
module.exports = {
  http: http
}
上一篇下一篇

猜你喜欢

热点阅读