首先是wtml
<swiper class="">//微信轮播图组件swiper <block wx:for="{{img_urls}}" wx:key="*this"> //block是标签 <swiper-item> <image src="{{item.img}}" class=""></image>//轮播的图片 </swiper-item> </block> </swiper >
然后是js,类似一个Ajax
wx.request({ // 获取轮播图 url: url, data: { custom_server: url2, }, success: function (res) { that.setData({ img_urls: }); } })
后台获取轮播图的方法
public function get_banner ($type = 2) { $where=array(); $server=$_SERVER['SERVER_NAME']; $cate = I('cate'); $where['type']=$type; if($server == ''){ if($cate == $type){ $where['orderid'] = array('between','220,240'); }else{ $where['orderid'] = array('not between','220,240'); } }$img_list=M('img')->where($where)->order('orderid desc')->field('id,img,url,orderid')->select(); if(!empty($img_list)){ foreach($img_list as $k2=>$v2){ $arr2=explode(',',$v2['url']); $info=$this->get_link($arr2['0'],$arr2['1'],$arr2['2']); $img_list[$k2]['path']=$info['src']; $img_list[$k2]['jump_type']=$info['jump_type']; } }else{ $where['type']=1; $img_list=M('img')->where($where)->order('orderid desc')->field('id,img,url')->select(); } $this->ajax_return('success', 1, $img_list); exit; }
轮播图的数据库表img中字段
img中存放的是图片的地址