// pages/homeContent/homeContent.js // // "lazyCodeLoading": "requiredComponents" //获取应用实例 const app = getApp(); Component({ /** * 继承父级样式 */ options: { addGlobalClass: true, }, // prop properties: { headerItem:String }, /** *组件的初始数据 */ data: { content:'子组件的content', homeHeaderItem:'', isLoading: true, article: {'key':12}, baseUrl:'https://yongma16.xyz/api/', path:'article/blog/', // 35, 34, 33, 32 currentArticleId:32, }, observers:{ }, lifetimes: { // 生命周期函数,可以为函数,或一个在 methods 段中定义的方法名 attached: function () { const id=app.homePageArticleId this.getRemoteArticle(id) }, moved: function () {}, detached: function () { }, }, // 生命周期函数,可以为函数,或一个在 methods 段中定义的方法名 // attached: function () { }, // 此处 attached 的声明会被 lifetimes 字段中的声明覆盖 // ready: function() { }, pageLifetimes: { // 组件所在页面的生命周期函数 show: function () { console.log('pageLifetimes') }, hide: function () { }, resize: function () { }, }, methods: { getRemoteArticle:function(id){ this.setData({ isLoading:true }) const baseUrl=this.data.baseUrl const path=this.data.path const headers = {'Content-Type':'application/json;charset=UTF-8'} const that=this const params={ id:id } wx.request({ url: baseUrl+path, headers:headers, data:params, method:'POST', success: (res) => { const data=res.data const articleStr=data&&data.article&&data.article const markdownText = app.towxml(articleStr,'markdown',{        theme:'light', //主题 dark 黑色,light白色,不填默认light        base: baseUrl+path, events:{ //为元素绑定的事件方法 tap:e => { console.log('tap',e); }, change:e => { console.log('todo',e); } } }); that.setData({ isLoading:false, article:markdownText }) } }); }, /** * 清空 */ clearArticle(){ this.setData({ article:null }) }, onMyButtonTap: function(){ this.setData({ // 更新属性和数据的方法与更新页面数据的方法类似 }) }, // 内部方法建议以下划线开头 _myPrivateMethod: function(){ // 这里将 data.A[0].B 设为 'myPrivateData' // this.setData({ // 'A[0].B': 'myPrivateData' // }) }, _propertyChange: function(newVal, oldVal) { } } })