慕尼黑4518828
2023-02-17 11:10
movielist下index.js代码如下:
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({env: cloud.DYNAMIC_CURRENT_ENV})
const axios = require('axios')
// 云函数入口函数
exports.main = async (event, context) => {
try {
const {
data
} = await axios({
url: `https://frodo.douban.com/api/v2/subject_collection/movie_showing/items?start=${event.start}&count=${event.count}&apiKey=054022eaeae0b00e0fc068c0c0a2102a`,
method: 'get',
headers: {
"Host": "frodo.douban.com",
"Connection": "keep-alive",
'content-type': 'application/json',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.2(0x18000236) NetType/WIFI Language/zh_CN',
'Referer': 'https://servicewechat.com/wx2f9b06c1de1ccfca/81/page-frame.html '
}
})
return data
} catch (e) {
console.log(e)
}
}
movie.js代码如下:
// pages/movie/movie.js
Page({
/**
* 页面的初始数据
*/
data: {
movieList:[]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
wx.cloud.callFunction({
name:'movielist',
data:{
start:this.data.movieList.length,
count:10
}
}).then(res =>{
console.log(res);
this.setData({
movieList: this.data.movieList.concat(res.result.subject_collection_items)
});
wx.hideLoading();
}).catch(err =>{
console.error(err);
wx.hideLoading();
});
},
gotoComment: function(event) {
wx.navigateTo({
url: `../comment/comment?movieid=${event.target.dataset.movieid}`,
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
轻松入门微信小程序与云开发
64580 学习 · 1742 问题
相似问题