北京网站建设公司怎么排版,企业网站开发主要职责,wordpress数据库详解,黑马大数据培训一、需求 接口返回的数据中既包含文字也包含图片#xff0c;并且需要对图片进行处理#xff08;设置最大宽度为100%并拼接域名#xff09; 可以按照以下步骤进行操作#xff1a;
二、代码
templatediv classdetailsdiv classinfos…一、需求 接口返回的数据中既包含文字也包含图片并且需要对图片进行处理设置最大宽度为100%并拼接域名 可以按照以下步骤进行操作
二、代码
templatediv classdetailsdiv classinfos v-htmlrenderContent(newsDetail.content)/div/div
/templatescriptexport default {data() {return {newsDetail: ,}},mounted() {this.initFun()},methods: {//1.获取到详情数据initFun() {var that this;this.$api.POST(this.$face.newsInfo, {id: that.id}, function(res) {that.newsDetail res.data.data;});},//2.处理包含文字和图片的字段并拼接图片的 URL 前缀或域名renderContent(content) {const imageUrlPrefix http://123.57.92.166/;const regex /img.*?src(.*?).*?/g;return content.replace(regex, (match, imageUrl) {const fullImageUrl imageUrlPrefix imageUrl;return img src${fullImageUrl} stylemax-width: 100%;;});},},}
/script完成~