// components/banner-swiper/banner-swiper.js const app = require('../../utils/util.js'); // const tools = require('../../utils/tools.js'); Component({ /** * 组件的属性列表 */ properties: { }, /** * 组件的初始数据 */ data: { indicatorDots: true, indicatorColor: 'rgb(255,255,255,1)', indicatorActiveColor: 'rgb(236,114,93,1)', autoplay: false, currentSwiper: 0, circular: true, interval: 3000, banners: [], // 轮播图 }, /** * 组件的生命周期 */ pageLifetimes: { show() { this.setData({ // currentSwiper: 0, autoplay: true }); }, hide() { this.setData({ autoplay: false }); // setTimeout(() => { // this.setData({ // currentSwiper: 0 // }); // }, 300); } }, async created() { // let sessionKey = await tools.checkSessionAndLogin(); wx.request({ url: app.globalData.publicUrl + '/wx/article/selArticleList', method: "post", data: { // sessionKey }, success: (res) => { // console.log('res--->', res); let {code, data} = res.data; if (code !== 0) { wx.showToast({ title: '获取文章列表失败!', }); return; } this.setData({ banners: data }); } }) }, /** * 组件的方法列表 */ methods: { changeSwiper(e) { let {current, source} = e.detail; if (source === 'touch') { this.setData({ currentSwiper: current }); } }, tapBanner(e) { let {id, title} = e.currentTarget.dataset; // link ='http://www.baidu.com'; wx.navigateTo({ url: `/pages/articleDetail/articleDetail?id=${id}&title=${encodeURI(title)}`, }); } } });