解决前
在js中获取后台的富文本数据后,使用 replace 设置图片的宽度为100%
<template>
<view class="container">
<rich-text :nodes="content"></rich-text>
</view>
</template>
<script>
import {
publicRequest
} from '@/services.js';
export default {
data() {
return {
content:''
}
},
onLoad(option) {
//设置头部导航栏标题
uni.setNavigationBarTitle({
title: option.title
})
publicRequest({
url: '接口地址',
method: 'get',
data: {
id: option.id
},
}).then(res => {
this.content = res.content.replace(/\<img/g, "<img style='width: 100%;'")
}).catch(err => {
console.log('err=', err)
})
}
}
</script>
完美解决!