欢迎光临,了解微信小程序开发,就上易用通!

微信小程序之scroll-view选项卡与跳转 (一)

发布:2018-04-25 09:00浏览: 来源:网络 作者:cola

大多数的商城类小程序都有这个功能,点击“全部订单”,“待付款”,“待发货”,“待收货”,“已完成”,会跳转页面且跳至与之相对应的选项卡中。所以我们在开发该小程序时也做了相同的功能。如下图:

微信小程序之scroll-view选项卡与跳转 (一)(图1)

但是我们在最后做交互的时候,并没有使用该效果,下篇再说这个!先说说这个效果是如何实现的!

选项卡静态布局思路: 主要用到 scroll-view与 swiper标签,选项卡切换主要依靠 swiper 中的 current 属性,不懂请自行查看小程序API。 
跳转页面且跳至与之相对应的选项卡思路: 
首先在 app.js 中配置 globalData。 
在“个人中心” js 文件中配置点击该项跳转至与之对应的 tab 的 index。 
在“个人中心”跳转页面时通过 globalData 传递 index 给“全部订单”页面,“全部订单”页面通过 app.globalData.currentLocation 接受数据,改变选项卡的切换。

app.js 代码

 

					
  1. globalData: {
  2. userInfo: null
  3. }

个人中心 wxml 代码

 

					
  1. <!--九宫格 -->
  2. <view class="page">
  3. <view class="page__bd">
  4. <view class="weui-grids">
  5. <view class="allrec" bindtap="allForm">
  6. <text>我的订单</text>
  7. <view class="more">查看更多订单</view>
  8. <image class='moreImg' src='../../img/more.png'></image>
  9. </view>
  10. <!--待付款 -->
  11. <view class="weui-grid" hover-class="weui-grid_active" bindtap="noPay">
  12. <image class="weui-grid__icon" src="../../img/wallet.png" />
  13. <view class="weui-badge" hidden="{{false}}">{{badgeNum1}}</view>
  14. <view class="weui-grid__label label">待付款</view>
  15. </view>
  16.  
  17. <!--待发货 -->
  18. <view class="weui-grid" hover-class="weui-grid_active" bindtap="noSend">
  19. <image class="weui-grid__icon" src="../../img/wallet-1.png" />
  20. <view class="weui-badge" hidden="{{false}}">{{badgeNum1}}</view>
  21. <view class="weui-grid__label label">待发货</view>
  22. </view>
  23.  
  24. <!--已发货 -->
  25. <view class="weui-grid" hover-class="weui-grid_active" bindtap="sended">
  26. <image class="weui-grid__icon" src="../../img/wallet-2.png" />
  27. <view class="weui-badge" hidden="{{false}}">{{badgeNum1}}</view>
  28. <view class="weui-grid__label label">待收货</view>
  29. </view>
  30.  
  31. <!--已完成 -->
  32. <view class="weui-grid" hover-class="weui-grid_active" bindtap="completed">
  33. <image class="weui-grid__icon" src="../../img/wallet-3.png" />
  34. <view class="weui-grid__label label">已完成</view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>

个人中心 js 代码

 

					
  1. var app = getApp()
  2. var util = require('../../utils/util.js')
  3. var formatLocation = util.formatLocation
  4.  
  5. Page({
  6. data: {
  7. },
  8. // 指定 全部订单 和 九宫格中按钮 点击跳转至 选项卡中 与之对应的tab
  9. allForm:function(){
  10. app.globalData.currentLocation = 0,
  11. wx.navigateTo({ url: '../orderForm/orderForm' })
  12. },
  13. noPay:function(){
  14. app.globalData.currentLocation = 1,
  15. wx.navigateTo({ url: '../orderForm/orderForm' })
  16. },
  17. noSend





免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。