// pages/home/home.js //获取应用实例 const app = getApp(); Page({ /** * 页面的初始数据 */ data: { title: 'header', userInfo: '', content: '我是父组件的content', footContent: "bottomContent", background: [{class:'header-swiper-one',content:'数据分析'}, {class:'header-swiper-two',content:'前端开发'}, {class:'header-swiper-three',content:'全栈开发'}], indicatorDots: true, headerContent:'swiper', vertical: false, autoplay: true, interval: 5000, duration: 1000, menuIsShow:false, bottomBtn:'front', titleObj:[], baseUrl:'https://yongma16.xyz/api/', path:'article/index/', currentArticleId:0, currentArticleTitle:'' }, // 监听 watch:{ bottomBtn:function(newVal,oldVal){ console.log('监听',newVal,oldVal) } }, /** * 获取文章 */ clickBlogTitleBtn(e){ const {id,title}=e.currentTarget.dataset this.setData({ currentArticleId:id, currentArticleTitle:title }) this.getRemoteArticleById(id) }, /** * 获取文章 * @param {*} id */ getRemoteArticleById(id){ const blogComponent=this.selectComponent('#blog-id') blogComponent.setLoading(true) const baseUrl=this.data.baseUrl const path=this.data.path const headers = {'Content-Type':'application/json;charset=UTF-8'} const params={ value:id } wx.request({ url: baseUrl+path, headers:headers, data:params, method:'POST', success: (res) => { const data=res.data const articleStr=data&&data.article[0] blogComponent.setArticleNode(articleStr) } }); }, /** * 更新菜单 * @param {Element} e */ updateArticleMenu(e){ console.log('info info',e.detail), this.setData({ titleObj:e.detail }) }, // 自定义函数 changeIndicatorDots() { this.setData({ indicatorDots: !this.data.indicatorDots }) }, changeAutoplay() { this.setData({ autoplay: !this.data.autoplay }) }, intervalChange(e) { this.setData({ interval: e.detail.value }) }, durationChange(e) { this.setData({ duration: e.detail.value }) }, // 关闭菜单 menuClose(){ this.data.menuIsShow&&this.setData({ menuIsShow: !this.data.menuIsShow }) }, menuSwitch(){ this.setData({ menuIsShow: !this.data.menuIsShow }) }, // 导航的按钮 clickBottomBtn(e){ const label=e.currentTarget.dataset.label||this.data.bottomBtn if(label==='target'||label==='life'){ return } this.setData({ bottomBtn:label }) }, getRemoteData(){ console.log('进入home页面' ,12431243) let url='https://yongma16.xyz/api/' let path='article/index/' wx.request({ url: url+path, method:'GET', success: (res) => { console.log('res2222',res) } }); }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getRemoteData() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })