uniapp renders html, parses rich text, rich-text components, supports class styles

Code directly

<template>
	<view class="container">
		<rich-text :nodes="html"></rich-text>
	</view>
</template>

<script>
	export default {
    
    
		data() {
    
    
			return {
    
    
				html: `<div style='color:red' class='classTest'>hello world</div>`
			}
		},
		methods: {
    
    

		}
	}
</script>

<style>
.classTest{
    
    
	color: blue !important;
}
</style>

effect

Insert picture description here

It can be seen that the classTest style is not rendered

Combined with the description of the official website

Insert picture description here

In other words, it supports class and style attributes, but class must be written in the global

Enter the App.vue file

Insert picture description here

<style>

.classTest{
    
    
	color: blue !important;
}
</style>

effect

Insert picture description here

Perfect solution

Guess you like

Origin blog.csdn.net/hu1628299958/article/details/114693627
Recommended