1 回复
自己琢磨了一下,目前能简陋的运行出来,代码如下:
获取新闻列表的js代码:
Page({
/**
* 页面的初始数据
*/
data: {
xinwen:[]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
wx.request({
url: 'http://v.juhe.cn/toutiao/index',
data:{
key:"聚合数据API提供的key",
type:"keji",
page:"1",
page_size:"10"
},
success:function(res){
console.log(res)
var xinwen = res.data.result.data;
that.setData({
xinwen : xinwen,
});
}
})
},
change:function(event){
const that = this
const index = event.target.dataset.index;
const xinwen = that.data.xinwen[index]
// console.log(index)
const uniquekey = xinwen.uniquekey;
console.log(uniquekey)
wx.navigateTo({
url: '../kejid/kejid?id='+uniquekey,
})
}
})
获取新闻列表的wxml代码:
<view class="container">
<view class="right-info">
<view class="title" wx:for="{{xinwen}}" wx:key="{{uniquekey}}" wx:for-index="index" data-index="{{index}}" bindtap="change" style="padding:10px;border-bottom:1px solid #e4e4e4">{{item.title}}
<view class="time">发布时间:{{item.date}}
</view>
</view>
</view>
</view>
获取新闻内容的js代码:
Page({
/**
* 页面的初始数据
*/
data: {
uniquekey:'',
detail:[],
content:""
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this
const uniquekey = options.id
console.log("uniqueky:"+uniquekey)
that.setData({
uniquekey:uniquekey
})
wx.request({
url: 'http://v.juhe.cn/toutiao/content',
data:{
key:"聚合数据API提供的key",
uniquekey:this.data.uniquekey
},
success:function(res){
// console.log(res)
var detail = res.data.result.detail;
var content = res.data.result.content
// console.log(detail)
that.setData({
detail:detail,
content:content
})
}
})
}
})
h获取新闻内容的WXML代码:
<text class="container">
<text class="top">
<text class="title">{{detail.title}}</text>
</text>
<text class="content">{{content}}</text>
</text>