getCurrentPages() 函数,可以获取当前页面栈的实例。
这个函数提供的页面栈以数组形式按栈的顺序给出,第一个元素为首页,最后一个元素为当前页面,所以倒数第二个元素就是上一页,我们可以使用这个函数实现无加载打开详情页,具体代码:
const loadArticle = function (id) {
let pages = getCurrentPages()
let count = pages.length;
let article = null;
if(count >=2 && (pages[count-2].data.is_list == true && pages[count-2].data.articles) ){
let articles = pages[count-2].data.articles.filter(item => item.id == id);
if(articles){
article = articles[0];
}
}
if(article){
this.setData({
article: article
})
}else{
// 使用 API 远程加载文章详情
}
}
let pages = getCurrentPages()
let count = pages.length;
let article = null;
if(count >=2 && (pages[count-2].data.is_list == true && pages[count-2].data.articles) ){
let articles = pages[count-2].data.articles.filter(item => item.id == id);
if(articles){
article = articles[0];
}
}
if(article){
this.setData({
article: article
})
}else{
// 使用 API 远程加载文章详情
}
}



