class Index { constructor() { this.home(); this.getType() this.initSwiper(); this.initHome(); } async getType() { var res = {}; if (localStorage.getItem("type") == null) { res = await indexService.type(); res.principal.unshift({ id: -1, page: 0, title: "首页" }) localStorage.setItem("type",JSON.stringify(res.principal)); } res = JSON.parse(localStorage.getItem("type")) res.forEach((v,i)=> { $(".menu_list").append(`
  • ${v.title}
  • `) }); res.forEach((v,i)=> { if (i > 0) { $(".swiper-wrapper").append(`

    ${v.title}

    `) } }) console.log(res) } async home () { var res = await indexService.home(); // $(".a").append(item(res.newest.data)) // $(".b").append(item(res.model.data)) console.log() console.log(res) } initHome() { new Swiper ('#modelSwiper', { direction: 'horizontal', // 如果需要分页器 pagination: { el: '.modelPagination', }, }); } initSwiper () { var mySwiper = new Swiper ('#pageSwiper', { direction: 'horizontal', on: { slideChangeTransitionEnd: function(){ $(".menu_list li").eq(this.activeIndex) .addClass("menu_active").siblings().removeClass("menu_active") }, }, }); $(".menu_list li").click(function () { $(this).addClass("menu_active").siblings().removeClass("menu_active"); mySwiper.slideTo($(this).index(),300) }) } } new Index();