| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <template>
- <!-- index.wxml -->
- <view class="wrap">
- <view class="wrap_nr">
- <rich-text :nodes="htmlSnip"></rich-text>
- </view>
- </view>
- </template>
- <script>
- // index.js
- let myPro = require('../../utils/wxRequest.js');
- let util = require('../../utils/util.js');
- export default {
- data() {
- return {
- 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
- },
- methods: {
- // 获取单页内容
- getContent() {
- let that = this;
- let params = {
- id: that.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);
- uni.showToast({
- title: err,
- icon: 'none'
- });
- });
- }
- }
- };
- </script>
- <style>
- /**index.wxss**/
- .richimg {
- width: 100% !important;
- height: auto !important;
- }
- .wrap_nr {
- padding: 30rpx;
- }
- </style>
|