(1)API路由跳页传参
(2)navigator导航组件跳页传参
商品列表展示页
代码如下:
//wxml
<view class="goodsList">
<view class="goodBox"
bindtap="toDetail"
wx:for="{{goods}}"
data-item="{{item}}"
wx:key="name">
<image src="{{item.imgSrc}}"></image>
<view>{{item.name}}¥{{item.price}}</view>
</view>
//返回顶部
<view class="toTop" bindtap="toTopFn">↑</view></view>
//wxss
.goodsList{
width: 100%;
height: auto;
display: flex;
justify-content: space-around;
flex-wrap: wrap;
}
.goodBox{
width: 45%;
height: 400rpx;
margin: 10rpx 0;
border: 1px solid rgba(0, 0, 0, 0.3);
border-radius: 6rpx;
}
.goodBox image{
width: 100%;
height: 330rpx;
display: block;
}
.goodBox view{
line-height: 70rpx;
font-size: 32rpx;
text-align:center;
}
.toTop{
position: fixed;
bottom: 5vh;
right: 5vw;
height: 100rpx;
width: 100rpx;
border-radius: 50%;
background-color: rgba(0,0,0,.2);
text-align: center;
line-height: 100rpx;
}
//js
/**
* 页面的初始数据
*/
data: {
goods:[
{ name: "雷神", price: 620, imgSrc:"http://n.sinaimg.cn/sinacn19/537/w1280h857/20180321/94aa-fyskeue3673333.jpg"},
{ name: "柴犬", price: 889, imgSrc: "http://i0.hdslb.com/bfs/article/3e914a016057a47ae4af8ee9ba33cd48f5294638.jpg" },
{ name: "博美", price: 808, imgSrc: "http://photocdn.sohu.com/20160229/mp61060060_1456732893510_8.jpeg" },
{ name: "哈士奇", price: 150, imgSrc: "http://photocdn.sohu.com/20151210/mp47737995_1449741148801_8.jpeg" },
{ name: "秋田犬", price: 153, imgSrc: "https://img.boqiicdn.com/Data/BK/A/1408/11/img60661407750795.jpg" },
{ name: "吉娃娃", price: 130, imgSrc: "http://photocdn.sohu.com/20150818/mp28013954_1439870034170_8.jpeg" },
]
},
toDetail(event){
const item=event.currentTarget.dataset.item;
console.log(item)
console.log(666)
wx.navigateTo({
url: '/pages/qiqi/hypermarket/goodDetail/goodDetail?name='+item.name+'&src='+item.imgSrc+'&price='+item.price,
success(){},
fail(){},
complete(){}
})
},
// 一键返回顶部
toTopFn(option) {
if (wx.pageScrollTo) {
wx.pageScrollTo({
scrollTop: 0
})
} else {
wx.showModal({
title: '提示',
content: '发生错误,无法使用该功能',
})
}
},
/**
* 页面上拉触底事件的处理函数 页面刷新效果
*/
onReachBottom: function () {
console.log("触发了上拉触底操作");
wx.showLoading({
title: '加载中',
});
const _this = this;
const timer = setTimeout(function () {
const newGoods = [
{ name: "雷神", price: 620, imgSrc: "http://n.sinaimg.cn/sinacn19/537/w1280h857/20180321/94aa-fyskeue3673333.jpg" },
{ name: "柴犬", price: 889, imgSrc: "http://i0.hdslb.com/bfs/article/3e914a016057a47ae4af8ee9ba33cd48f5294638.jpg" },
{ name: "博美", price: 808, imgSrc: "http://photocdn.sohu.com/20160229/mp61060060_1456732893510_8.jpeg" },
{ name: "哈士奇", price: 150, imgSrc: "http://photocdn.sohu.com/20151210/mp47737995_1449741148801_8.jpeg" },
{ name: "秋田犬", price: 153, imgSrc: "https://img.boqiicdn.com/Data/BK/A/1408/11/img60661407750795.jpg" },
{ name: "吉娃娃", price: 130, imgSrc: "http://photocdn.sohu.com/20150818/mp28013954_1439870034170_8.jpeg" },
];
_this.setData({
goods: _this.data.goods.concat(newGoods)
});
wx.hideLoading();
clearTimeout(timer);
}, 1000)
},
以上就是一个小案例 有问题随时咨询小编!!!