const towxml = require('./index.js'); Component({ options:{ styleIsolation:'shared' }, properties:{ nodes:{ type:Object, value:{} }, markdown:{ type:String, value:'' }, theme:{ type:String, value:'light' } }, observers:{ 'markdown': function(markdown){ if(markdown && typeof markdown === 'string'){ try{ const nodes = towxml(markdown, 'markdown', { theme: this.data.theme || 'light', base: '' }); this.setData({ nodes: nodes }); }catch(error){ console.error('Markdown 转换失败:', error); } } } }, data:{ nodes:{} }, lifetimes:{ attached(){ // 如果传入了 markdown 文本,进行转换 if(this.properties.markdown){ try{ const nodes = towxml(this.properties.markdown, 'markdown', { theme: this.properties.theme || 'light', base: '' }); this.setData({ nodes: nodes }); }catch(error){ console.error('Markdown 转换失败:', error); } } } } })