
<!--home.wxml-->
<import src="menu/menu-template.wxml" />
<import src="book/book-template.wxml" />
<import src="header/header-template.wxml" />
<view class="container">
<swiper indicator-dots="{{true}}" indicator-color="#fff" indicator-active-color="#FB7C58">
<swiper-item wx:for="{{banners}}" >
<image class="swiper-image" src="{{item.picUrl}}" mode="scaleToFill"></image>
</swiper-item>
</swiper>
<view class="menu">
<block wx:for="{{menus}}">
<view catchtap="toHotPush" data-index="{{index}}">
<template is="menu" data="{{...item}}"></template>
</view>
</block>
</view>
<view class="content">
<block wx:for="{{books}}">
<template is="header" data="{{...item.header}}"></template>
<view wx:for="{{item.books}}" catchtap="toDetail" data-book="{{item}}">
<template is="book" data="{{...item}}"></template>
</view>
<view class="separation"></view>
</block>
</view>
</view>
|
/* home.wxss */
@import "menu/menu-template.wxss";
@import "book/book-template.wxss";
@import "header/header-template.wxss";
.container {
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
background-color: #eee;
padding: 0rpx;
}
swiper {
width: 100%;
height: 400rpx;
}
.swiper-image {
width: 100%;
height: 400rpx;
padding: 0rpx;
}
.menu {
width: 100%;
height: 160rpx;
background-color: #fff;
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center;
border-bottom: 1px solid #eee;
margin-bottom: 20rpx;
}
.content {
background-color: #fff;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
}
.separation {
width: 100%;
height: 20rpx;
background-color: #eee;
}
|
// home.js
Page({
/**
* 页面的初始数据
*/
data: {
banners: [],
books: [
{ header: {name: "精品图书"}, books: [] },
{ header: {name: "随便看看"}, books: [] },
{ header: {name: "最新上架"}, books: [] },
],
menus: [
{ "imgUrl": "/images/menu/rank.png", "name": "榜单" },
{ "imgUrl": "/images/menu/category.png", "name": "分类" },
{ "imgUrl": "/images/menu/list.png", "name": "书单" },
{ "imgUrl": "/images/menu/active.png", "name": "活动" }
]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.requestData();
},
requestData: function () {
var that = this;
wx.request({
url: 'http://www.kindlepush.com/app/getIndexInfo',
success: function (res) {
//console.log(res.data.hotBookList);
// that.data.banners = res.data.pictureList;
// that.data.books[0].books = res.data.goodBookList;
// that.data.books[1].books = res.data.hotBookList;
// that.data.books[2].books = res.data.newBookList;
//以上方式不可以
that.setData({
banners: res.data.pictureList,
'books[0].books': res.data.goodBookList,//注意加引号
'books[1].books': res.data.hotBookList,
'books[2].books': res.data.newBookList,
});
},
fail: function (err) {
console.log(err);
}
});
},
toDetail:function(event){
var book = event.currentTarget.dataset.book;
wx.navigateTo({
url: '/pages/bookDetail/bookDetail?book='+JSON.stringify(book),
})
},
toHotPush: function(event){
var index=event.currentTarget.dataset.index;
if (index==0){
wx.navigateTo({
url: '/pages/hotPush/hotPush',
})
}else{
wx.showToast({
title: '暂无此功能!',
duration: 1000,
})
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
|
模板简介:该模板名称为【微信小程序集思会精品图书图片展示页面样式设计制作开发教程】,大小是,文档格式为.,推荐使用打开,作品中的图片,文字等数据均可修改,图片请在作品中选中图片替换即可,文字修改直接点击文字修改即可,您也可以新增或修改作品中的内容,该模板来自用户分享,如有侵权行为请联系网站客服处理。欢迎来懒人模板【小程序教程】栏目查找您需要的精美模板。