小程序模板网

微信小程序商品到详情(传参)

发布时间:2017-12-19 10:38 所属栏目:小程序开发教程

商品页 post.wxmldata-postid="{{index}}view class="container" swiper indicator-dots indicator-color="rgba(255,255,255,0.3)" indicator-active-color="rgba(255,255,255,1)" autoplay swiper-item image src= ...

 
 
 

商品页 post.wxml

data-postid="{{index}}

 

		
  1. <view class="container">
  2. <swiper indicator-dots indicator-color="rgba(255,255,255,0.3)" indicator-active-color="rgba(255,255,255,1)" autoplay>
  3. <swiper-item>
  4. <image src="/dist/images/wx.png"></image>
  5. </swiper-item>
  6. <swiper-item>
  7. <image src="/dist/images/vr.png"></image>
  8. </swiper-item>
  9. <swiper-item>
  10. <image src="/dist/images/iqiyi.png"></image>
  11. </swiper-item>
  12. </swiper>
  13. <view class="article-list">
  14. <view class="article" wx:for="{{postList}}" wx:for-item="article" wx:key="index" catchtap="goDetail" data-postid="{{index}}">
  15. <view class="article-author-date">
  16. <image src="{{article.avatar}}" class="article-author"></image>
  17. <text class="article-date">{{article.date}}</text>
  18. </view>
  19. <text class="article-title">{{article.title}}</text>
  20. <image src="{{article.imgSrc}}" class="article-image"></image>
  21. <text class="article-content">
  22. {{article.content}}
  23. </text>
  24. <view class="article-link">
  25. <image src="/dist/images/icon/chat1.png"></image>
  26. <text>{{article.collection}}</text>
  27. <image src="/dist/images/icon/view.png"></image>
  28. <text>{{article.reading}}</text>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
 

post.js

en对象获取postid

 

		
  1. var postData = require ("../../data/posts-data.js");
  2. Page({
  3. onLoad:function(){
  4. this.setData({
  5. postList:postData.postList
  6. })
  7. },
  8.  
  9. goDetail:function(en){
  10.  
  11. var postid = en.currentTarget.dataset.postid;
  12. wx.navigateTo({
  13. url:"post-detail/post-detail?postId="+postid
  14. })
  15. }
  16. })
 

商品详情页 post-detail.js

用option接收postid

 

		
  1. var postData = require("../../../data/posts-data.js");
  2. Page({
  3. onLoad:function(option){
  4. console.log(option);
  5. }
  6. })


易优小程序(企业版)+灵活api+前后代码开源 码云仓库:starfork
本文地址:https://www.eyoucms.com/wxmini/doc/course/18209.html 复制链接 如需定制请联系易优客服咨询:800182392 点击咨询
QQ在线咨询