<script> export default { data() { return { height: 0, start: 0, // 默认第1页 count: 10, //每条显示的数量 movieData: [], //数据 }; }, mounted() { let that = this;
// 获取设备宽度 uni.getSystemInfo({ success: function(res) { that.height = res.windowHeight; } });
//初始化数据 uni.request({ url: 'https://api.douban.com/v2/movie/top250', dataType: 'JSON', data: { start: that.start, count: that.count }, success(res) { that.movieData = res.data.subjects; } }); }, methods: { // 滚动到底触发的事件 ButtonClick() { uni.showLoading({ title: '加载中...' });
let that = this; // 因为这个没有最大的页数。我只能这样子写 if (that.start) { that.start += 1; }
//触发请求 uni.request({ url: 'https://api.douban.com/v2/movie/top250', dataType: 'JSON', data: { start: that.start, count: that.count }, success(res) { that.movieData = res.data.subjects; // 这个拼接到数组里面就ok了 res.data.subjects.forEach(item => { // 遍历数组,拼接 that.movieData.push(item); });
// 回调成功 就关闭加载框 uni.hideLoading();
//在提示一下,加载成功 uni.showToast({ title: '成功', duration: 2000 }); } }); } } }; </script>
<style> .li { display: flex; align-items: center; } .li image { width: 160upx; height: 200upx; } </style>
|