ElNotification({ message: successMessage, dangerouslyUseHTMLString: true, type: 'success',这样自定义样式引入正确吗
时间: 2024-03-10 18:44:42 浏览: 3
是的,这样可以在 Element Plus Notification 组件中使用自定义 HTML 字符串,并正确地应用自定义样式。
使用 `dangerouslyUseHTMLString` 属性可以告诉组件,你正在使用自定义 HTML 字符串,并且允许你在 HTML 代码中使用样式属性。然后,你可以在 HTML 代码中添加自定义样式,例如:
```
ElNotification({
message: '<div style="background-color: #67C23A; color: #fff;">' + successMessage + '</div>',
dangerouslyUseHTMLString: true,
type: 'success'
});
```
这样就可以将自定义样式应用到 Element Plus Notification 组件中,并且不会出现乱码或混乱的情况。需要注意的是,你需要确保你的样式代码是有效的 CSS 代码,否则可能会导致样式无法正确应用。
相关问题
ElNotification({ message: successMessage, dangerouslyUseHTMLString: true, type: 'success', customClass: 'my-notification-success' // 添加自定义类名 })字体颜色怎么设置
你可以通过添加 CSS 样式来设置 ElNotification 组件的字体颜色。具体的做法是,在你的样式表中添加以下代码:
```css
.my-notification-success .el-notification__content {
color: #fff; /* 设置字体颜色 */
}
```
这样,当你调用 ElNotification 组件时,添加了 `my-notification-success` 类名后,通知框的字体颜色就会变成白色。你可以根据需要修改 CSS 中的颜色值。
ElNotification({ message: errorMessage, dangerouslyUseHTMLString: true, type: 'error', })怎么修改通知样式
可以通过修改样式来改变ElNotification的通知样式。具体步骤如下:
1. 打开浏览器的开发者工具,找到通知弹窗的CSS样式。
2. 根据需要修改相应的CSS样式,例如修改背景颜色、字体大小、边框等。
3. 将修改后的CSS样式添加到项目中,可以使用以下方式:
```css
.el-notification__group {
background-color: #fff;
border: 1px solid #ddd;
font-size: 16px;
color: #333;
}
```
4. 在ElNotification中添加自定义的class名称,例如:
```javascript
ElNotification({
message: errorMessage,
dangerouslyUseHTMLString: true,
type: 'error',
customClass: 'my-notification'
})
```
5. 在自定义的CSS样式中添加对应的class样式,例如:
```css
.my-notification .el-notification__group {
background-color: #fff;
border: 1px solid #ddd;
font-size: 16px;
color: #333;
}
```
这样就可以自定义ElNotification的通知样式了。