| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- // index.js
- let myPro = require("../../utils/wxRequest.js");
- let util = require("../../utils/util.js");
- Page({
- data: {
- id: '',
- htmlSnip: ''
- },
- onLoad: function (options) {
- // Do some initialize when page load.
- let that = this;
- that.setData({
- id: options.id
- });
- },
- onShow: function () {
- // Do something when page show.
- let that = this;
- that.getContent();
- },
- onReady: function () {
- // Do something when page ready.
- },
- onHide: function () {
- // Do something when page hide.
- },
- onUnload: function () {
- // Do something when page close.
- },
- onPullDownRefresh: function () {
- // Do something when pull down.
-
- },
- onReachBottom: function () {
- // Do something when page reach bottom.
- },
- onPageScroll: function () {
- // Do something when page scroll
-
- },
- onResize: function () {
- // Do something when page resize
- },
- // 获取单页内容
- getContent(){
- let that = this;
- let params = {
- id: that.data.id
- };
- myPro.wxRequest("user/v3/article/detail","GET",params).then(res=>{
- let contents = res.result.content;
- // 小程序内置,转富文本标签,仅对rich-text 中的 class 生效
- contents = contents.replace(/\<img /g, '<img class="richimg" ');
- // contents = contents.replace(/\<img src\=\"\/upload/g, '<img class="richimg" src="'+ that.data.domain +'upload');
- contents = contents.replace(/\<p/g, '<p class="richtxt" ');
- contents = contents.replace(/\<br\>/g, '')
- that.setData({
- htmlSnip: contents
- });
- }).catch(err=>{
- console.log('报错信息',err);
- wx.showToast({
- title: err,
- icon: "none"
- })
- })
- }
- });
|