tanzhongheY/pages/details/details.js

102 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// pages/details.js
var urlPath = require('../../config.js');
Page({
/**
* 页面的初始数据
*/
data: {
oneData: {}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
this.getOneData(options.id)
},
getOneData: function(id) {
var that = this
wx.request({
url: urlPath.newsDetail,
header: {
'content-type': 'application/x-www-form-urlencoded' // 改变默认值为这个配置
},
dataType: 'json', // 添加这个配置
method: 'post',
data: {
id: id
},
success(res) {
var oneData = res.data.data;
var jsonDa = JSON.parse(oneData).content.replace(/<img/gi,
"< img class='richImg'style='width:auto!important;height:auto!important;max-height:100%;width:100%;'"
);
//遍历得到的数据给img添加CSS和style
var newResData = (jsonDa);
// console.log(newResData); //得到的数据含有img标签的都有richImg类
that.setData({
newResData: newResData,
})
if (res.data.result == 'success') {
that.setData({
oneData: JSON.parse(res.data.data)
})
} else {
console.log(res.data.msg); //失败
}
}
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
}
})