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

幻灯片,tab导航切换

发布:2018-01-25 11:41浏览: 来源:网络 作者:tianshu

  • 使用微信小程序原生组件swiper实现。


  1. <swiper 
  2.         indicator-dots="{{indicatorDots}}" 
  3.         autoplay="{{autoplay}}" 
  4.         interval="{{interval}}" 
  5.         duration="{{duration}}">
  6.         <block wx:for="{{imgUrls}}" wx:key="index">
  7.             <swiper-item>
  8.                 <image src="{{item}}" class="slide-image" 
  9.                 mode="scaleToFill"/>
  10.             </swiper-item>
  11.         </block>
  12.     </swiper>

配合在逻辑页面配置数据实现幻灯片

  1. Page({
  2.         data: {
  3.             imgUrls: [],
  4.             indicatorDots: true,
  5.             autoplay: true,
  6.             interval: 2000,
  7.             duration: 1000,
  8.         },
  9.         onLoad: function(){
  10.             util.ajax({
  11.                 url: 'https://api.zg5v.com/index.php/index/show/banner',
  12.                 data: {
  13.                     uid: 194
  14.                 },
  15.                 cb: function(res) {
  16.                     setSilde.call(self, res.data.data);
  17.                 }
  18.             });
  19.         }
  20.     })
tab导航切换
  • 由于微信小程序不能直接操作DOM,所以这里设置一个data-id值。(data-id="{{index}}" )用来模拟DOM操作,来实现导航内容的切换


  1. <view class="nav-warp">
  2.         <view class="tab">
  3.             <block wx:for="{{navItem}}" wx:key="index">
  4.                 <text bindtap="navToggle" 
  5.                     data-id="{{index}}" 
  6.                     class="tab-txt 
  7.                             {{showItem == index ? 'active' : '' }}">
  8.                     {{item}}
  9.                 </text>
  10.             </block>
  11.         </view>
  12.     </view>

用于模拟DOM操作

  1. Page({
  2.         data: {
  3.             showItem: 0
  4.         },
  5.         navToggle: function(e){
  6.             this.setData({
  7.                 showItem: e.target.dataset.id    
  8.             });
  9.             util.dataList.call(this, {
  10.                 url: 'https://api.zg5v.com/index.php/index/show/qtshow',
  11.                 data: {
  12.                     uid: 148,
  13.                     fenid: e.target.dataset.id - 1,
  14.                     num: 0
  15.                 },
  16.                 cb: util.petAge
  17.             });
  18.         }   
  19.     });





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