Authored by ccbikai

为您优选异步化

@@ -5,14 +5,23 @@ @@ -5,14 +5,23 @@
5 */ 5 */
6 6
7 7
8 -var Swiper = require('yoho.iswiper'); 8 +var Swiper = require('yoho.iswiper'),
  9 + $ = require('jquery');
9 10
10 -var recommendSwiper; 11 +var recommendSwiper,
  12 + $recommendForYou = $('.recommend-for-you');
11 13
12 -recommendSwiper = new Swiper('#swiper-recommend', {  
13 - slidesPerView: 'auto',  
14 - grabCursor: true,  
15 - slideElement: 'li',  
16 - lazyLoading: true,  
17 - watchSlidesVisibility: true 14 +$.get('/home/preference').then(function(html) {
  15 + $recommendForYou.html(html);
  16 + if ($('#swiper-recommend').length) {
  17 + recommendSwiper = new Swiper('#swiper-recommend', {
  18 + slidesPerView: 'auto',
  19 + grabCursor: true,
  20 + slideElement: 'li',
  21 + lazyLoading: true,
  22 + watchSlidesVisibility: true
  23 + });
  24 + }
  25 +}).fail(function() {
  26 + $recommendForYou.hide();
18 }); 27 });
  1 +<div class="title">为您优选新品</div>
  2 +<div id="swiper-recommend" class="swiper-container">
  3 + <ul class="swiper-wrapper swiper-wrapper-recommend">
  4 + {{#recommendList}}
  5 + <li class="swiper-slide">
  6 + <img class="swiper-lazy img-box" data-src="{{thumb}}">
  7 + <div class="price">
  8 + <span class="sale-price {{^price}}no-price{{/price}}">¥{{salePrice}}</span>
  9 + {{#price}}<span class="old-price">¥{{.}}</span>{{/price}}
  10 + </div>
  11 + <div class="swiper-lazy-preloader"></div>
  12 + </li>
  13 + {{/recommendList}}
  14 + </ul>
  15 +</div>
1 -{{# recommendForYou}}  
2 - <div class="recommend-for-you">  
3 - <div class="title">为您优选新品</div>  
4 - <div id="swiper-recommend" class="swiper-container">  
5 - <ul class="swiper-wrapper swiper-wrapper-recommend">  
6 - {{#recommendList}}  
7 - <li class="swiper-slide">  
8 - <img class="swiper-lazy img-box" data-src="{{thumb}}">  
9 - <div class="price">  
10 - <span class="sale-price {{^price}}no-price{{/price}}"{{salePrice}}</span>  
11 - {{#price}}<span class="old-price"{{.}}</span>{{/price}}  
12 - </div>  
13 - <div class="swiper-lazy-preloader"></div>  
14 - </li>  
15 - {{/recommendList}}  
16 - </ul>  
17 - </div>  
18 - </div>  
19 -{{/ recommendForYou}}  
  1 +<div class="recommend-for-you">
  2 +</div>