<template> <view class="page"> <u-navbar title="用车指南" :border-bottom="false" :background="bgc" title-color='#000' title-size='36' height='45'></u-navbar> <view class="cont" v-html="content"></view> </view> </template> <script> export default { data() { return { bgc: { backgroundColor: "#fff", }, content: '' } }, onLoad() { this.getword() }, methods: { // getclass() { // this.$u.get("/app/classify/list?&parentId=111?&classifyId=114" ).then((res) => { // if (res.code == 200) { // this.classlist = res.data // let id =this.classlist[0].classifyId // this.getword(id) // } else { // // uni.showToast({ // // title: res.msg, // // icon: 'none', // // duration: 2000 // // }); // } // }); // }, getword() { this.$u.get("/app/article/list?classifyId=" + 100).then((res) => { if (res.code == 200) { let abb = res.rows.find(item => item.articleId == 19); this.content = abb.content this.content = this.replaceImgWithImage(this.content) } else { // uni.showToast({ // title: res.msg, // icon: 'none', // duration: 2000 // }); } }); }, replaceImgWithImage(content) { // 替换所有的 为 \u00A0 content = content.replace(/ /g, '\u00A0'); // 替换 <img> 标签的宽度和高度样式 content = content.replace(/<img([^>]*)>/g, (match, group1) => { // 查找并移除可能存在的尾部斜杠 let cleanedGroup = group1.replace(/\s*\/$/, ''); return `<img style="width: 85vw ; height: auto;" ${cleanedGroup} />`; }); return content; } } } </script> <style lang="scss"> page { background-color: #fff; } .page { width: 750rpx; padding-bottom: 100rpx; .cont { margin-top: 34rpx; margin: 0 auto; width: 634rpx; } } </style>