<el-table-column label="详情介绍" prop="intro" :formatter="removeHtmlStyle" show-overflow-tooltip />
<el-table-column :formatter="formatFromDict" label="户型" prop="houseType" show-overflow-tooltip />
//获取的字典数据
import { formatDict} from '@/utils/dict'
const removeHtmlStyle = (row, column, cellValue) => {
const html = cellValue
const relStyle = /style\s*?=\s*?([‘"])[\s\S]*?\1/g //去除样式
const relTag = /<.+?>/g //去除标签
const relClass = /class\s*?=\s*?([‘"])[\s\S]*?\1/g // 清除类名
let newHtml = ''
if (html) {
newHtml = html.replace(relStyle, '')
newHtml = newHtml.replace(relTag, '')
newHtml = newHtml.replace(relClass, '')
}
return newHtml
}
const formatFromDict = (row, column, cellValue) => {
let type = null
if (column.property === 'houseType') {
type = 'house_type'
}
return formatDict(type, cellValue)
}
el-table内如何解析富文本只取文字和取字典转换
于 2024-01-05 10:04:30 首次发布