1. 程式人生 > >微信小程式商品到詳情

微信小程式商品到詳情

微信小程式商品到詳情結構程式碼資源分享給大家.

商品頁 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. goDetail:function(en){
  9. var postid = en.currentTarget.dataset.postid;
  10. wx.navigateTo({
  11. url:"post-detail/post-detail?postId="+postid
  12. })
  13. }
  14. })

商品詳情頁 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. })