import Vue from 'vue' // 日期格式化 export function formatterDate(date, flag = '-', mode = 'date') { const year = new Date(date).getFullYear() const month = new Date(date).getMonth() + 1 const day = new Date(date).getDate() return `${year}${flag}${month > 9 ? month : '0' + month}${flag}${day > 9 ? day : '0' + day}` } export function formatContent(html) { // 去掉img标签里的style、width、height属性 let contentData = html.replace(/]*>/gi, function(match, capture) { match = match.replace(`style=""`, '') match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '') match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '') match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '') return match }) // 修改所有style里的width属性为max-width:100% contentData = contentData.replace(/style="[^"]+"/gi, function(match, capture) { match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;'); return match }) // 去掉
标签 contentData = contentData.replace(/]*\/>/gi, '') // img标签添加style属性:max-width:100%;height:auto contentData = contentData.replace(/\