crawler-MiniProgram/新闻小程序/pages/news-detail/news-detail.js

82 lines
1.5 KiB
JavaScript

// pages/news-detail/news-detail.js
let newsType = '';
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// console.log('从主页传递来的id:', options.id)
// console.log('从主页传递来的currentIndex:', options.currentIndex)
let currentIndex = options.currentIndex
if (currentIndex == 0) {newsType='nd-news'}
else if (currentIndex == 1) {newsType='xg-news'}
else if (currentIndex == 2) {newsType='tw-news'}
else if (currentIndex == 3) {newsType='gj-news'}
else if (currentIndex == 4) {newsType='junshi-news'}
wx.cloud.database().collection(newsType).doc(options.id)
.get()
.then(res => {
console.log('请求成功', res)
this.setData({
detail: res.data,
news_image: res.data.news_img,
})
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})