微信小程序_豆瓣电影

441 阅读1分钟

接口

http://t.yushu.im/v2/movie/in_theaters 电影
http://t.yushu.im/v2/movie/coming_soon 即将上映
http://t.yushu.im/v2/movie/top250      前250

search 
http://t.yushu.im/v2/movie/search?q="" 搜索
http://t.yushu.im/v2/movie/subject/1764796 详情

设置不校验域名

目录结构

首页

将首页拆分成以下部分,通过

<import src="search/search.wxml"/>
<import src="movie-list/movie-list.wxml"/>
<template is="search"></template>
<template is="movie-list" data="{{...inTheaters}}"></template>
<template is="movie-list" data="{{...comingSoon}}"></template>
<template is="movie-list" data="{{...top250}}"></template>

请求数据

function fetchData(url) {
    var promise = new Promise((resolve, reject) => {
        wx.request({
            url,
            data: {},
            method: 'GET',
            header: {
                //访问豆瓣 不能给application
                'content-type': 'json'
            },
            success: resolve,
            fail: reject,
        })
    });
    return promise;
}

查看项目