element-ui关闭notify
时间: 2024-05-27 21:07:09 浏览: 20
在element-ui中,关闭notify的方法有两种:
1. 调用notify方法时传入duration参数为0,即不显示notify弹窗。
2. 调用notify的close方法,该方法可以手动关闭notify弹窗。
具体代码如下:
1. 不显示notify弹窗
```
this.$notify({
title: '标题名称',
message: '提示信息',
duration: 0 // 不显示notify弹窗
})
```
2. 手动关闭notify弹窗
```
let notify = this.$notify({
title: '标题名称',
message: '提示信息'
})
notify.close() // 手动关闭notify弹窗
```
相关问题
element-ui $notify
element-ui 的 $notify 是一个全局提示组件,可以方便地在页面的任何位置弹出提示框,常用于表单提交成功、失败等提示信息的展示。
使用方法如下:
1. 在 main.js 中引入 element-ui:
```
import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
```
2. 在需要使用 $notify 的组件中,通过 this.$notify(options) 调用:
```
this.$notify({
title: '成功',
message: '这是一条成功的提示消息',
type: 'success'
});
```
其中,options 是一个对象,包含以下属性:
- title:提示框的标题
- message:提示框的内容
- type:提示框的类型,可选值有 success、warning、info、error
element-ui $notify点击事件
element-ui 的 $notify 组件并没有提供点击事件的回调函数,但是可以通过以下方式实现:
1. 使用 $notify 函数的返回值,即 Notification 实例,手动绑定 click 事件:
```
const notification = this.$notify({
title: '标题',
message: '内容'
});
notification.$el.addEventListener('click', () => {
// 点击事件回调函数
});
```
2. 使用 $notify 函数的 options 参数中的 onClose 回调函数,在关闭通知时触发点击事件:
```
this.$notify({
title: '标题',
message: '内容',
onClose: () => {
// 点击事件回调函数
}
});
```