const api = require('../../utils/api.js'); Page({ data: { article: null, loading: true, error: '', }, onLoad(options) { const id = options.id; if (!id) { this.setData({ loading: false, error: '文章不存在' }); return; } api .getArticle(id) .then((a) => this.setData({ article: a, loading: false })) .catch((e) => this.setData({ loading: false, error: e.message || '加载失败' })); }, // 从文章跳到对应的记录入口 goRecord() { wx.switchTab({ url: '/pages/record/record' }); }, onShareAppMessage() { const a = this.data.article; return { title: a ? a.title : '肉垫计划 · 新手养宠知识', path: a ? `/pages/article/article?id=${a.id}` : '/pages/home/home', }; }, });