Notification
Notification (알림)
누군가에게 뭔가를 알려야 할 때 사용하는 컴포넌트예요. Notification은 항상 우선순위가 낮은(piority) 메시지라서, 원문 필자도 여기에 쓸데없는 애니메이션을 많이 넣을 수 있었다고 농담하죠.
notification을 사용하려면 관련 메서드를 호출하는 컴포넌트를 n-notification-provider로 감싸고 useNotification으로 API를 가져와야 해요.For example:
<!-- App.vue -->
<n-notification-provider>
<content />
</n-notification-provider>
import { useNotification } from 'naive-ui'
import { defineComponent } from 'vue'
// content
export default defineComponent({
setup() {
const notification = useNotification()
return {
warning() {
notification.warning({
content: '...'
})
}
}
}
})
출처: 문서
본문
Demos
basic.vue
type.vue
change-content.vue
scrollable.vue
closable.vue
duration.vue
max.vue
placement.vue
API
NotificationProvider Props
| 이름 | 타입 | 기본값 | 설명 | 버전 |
|---|---|---|---|---|
| container-class | string |
undefined |
알림 컨테이너의 클래스예요. | 2.36.0 |
| container-style | string | Object |
undefined |
알림 컨테이너의 스타일이에요. | 2.25.0 |
| placement | 'top' | 'bottom' |'top-right' | 'top-left' | 'bottom-left' | 'bottom-right' |
'top-right' |
모든 알림의 위치예요. | 'top' | 'bottom' 2.29.0 |
| max | number |
undefined |
표시할 알림의 개수를 제한해요. | |
| scrollable | boolean |
true |
알림을 스크롤할 수 있는지 여부예요. placement가 'top' 또는 'bottom'일 때는 사용할 수 없어요. |
|
| to | string | HTMLElement |
'body' |
알림 컨테이너의 컨테이너 노드예요. |
notification Injection Methods
| 이름 | 타입 | 설명 |
|---|---|---|
| create | (option: NotificationOption) => NotificationReactive |
알림을 만들어요. |
| destroyAll | () => void |
표시 중인 모든 알림을 제거해요. |
| error | (option: NotificationOption) => NotificationReactive |
error 타입 알림을 사용해요. |
| info | (option: NotificationOption) => NotificationReactive |
info 타입 알림을 사용해요. |
| success | (option: NotificationOption) => NotificationReactive |
success 타입 알림을 사용해요. |
| warning | (option: NotificationOption) => NotificationReactive |
warning 타입 알림을 사용해요. |
NotificationOption Properties
| 이름 | 타입 | 기본값 | 설명 | 버전 |
|---|---|---|---|---|
| action | string | (() => VNodeChild) |
undefined |
작업 영역의 콘텐츠예요. 렌더 함수를 사용할 수 있어요. | |
| avatar | () => VNodeChild |
undefined |
avatar의 콘텐츠예요. |
|
| closable | boolean |
true |
닫기 아이콘을 표시할지 여부예요. | |
| content | string | (() => VNodeChild) |
undefined |
콘텐츠예요. 렌더 함수를 사용할 수 있어요. | |
| description | string | (() => VNodeChild) |
undefined |
description의 콘텐츠예요. 렌더 함수를 사용할 수 있어요. |
|
| duration | number |
undefined |
지정하지 않으면 자동으로 닫히지 않아요. 단위는 밀리초예요. | |
| keepAliveOnHover | boolean |
false |
마우스를 올려두면 알림을 유지할지 여부예요. | 2.32.0 |
| meta | string | (() => VNodeChild) |
undefined |
meta의 콘텐츠예요. 렌더 함수를 사용할 수 있어요. |
|
| title | string | (() => VNodeChild) |
undefined |
title의 콘텐츠예요. 렌더 함수를 사용할 수 있어요. |
|
| onAfterEnter | Function |
undefined |
Transition의 enter 애니메이션이 실행된 뒤에 발생하는 콜백이에요. | |
| onAfterLeave | Function |
undefined |
Transition의 leave 애니메이션이 실행된 뒤에 발생하는 콜백이에요. | |
| onClose | () => boolean | Promise<boolean> |
undefined |
알림이 닫힐 때의 콜백이에요. false를 반환하거나, promise가 false로 resolve되거나 reject되면 이 닫힘이 취소돼요. |
|
| onLeave | Function |
undefined |
Transition의 leave 애니메이션이 실행될 때 발생하는 콜백이에요. |
NotificationReactive API
NotificationReactive Properties
NotificationReactive의 속성은 동적으로 바꿀 수 있어요.
| 이름 | 타입 | 설명 |
|---|---|---|
| action | string | (() => VNodeChild) |
작업 영역의 콘텐츠예요. 렌더 함수를 사용할 수 있어요. |
| avatar | () => VNodeChild |
avatar의 콘텐츠예요. 렌더 함수를 사용할 수 있어요. |
| closable | boolean |
닫기 아이콘을 표시할지 여부예요. |
| content | string | (() => VNodeChild) |
콘텐츠예요. 렌더 함수를 사용할 수 있어요. |
| description | string | (() => VNodeChild) |
description의 콘텐츠예요. 렌더 함수를 사용할 수 있어요. |
| duration | number |
지정하지 않으면 자동으로 닫히지 않아요. 단위는 밀리초예요. |
| meta | string | (() => VNodeChild) |
meta의 콘텐츠예요. 렌더 함수를 사용할 수 있어요. |
| title | string | (() => VNodeChild) |
title의 콘텐츠예요. 렌더 함수를 사용할 수 있어요. |
| onAfterEnter | Function |
Transition의 enter 애니메이션이 실행된 뒤에 발생하는 콜백이에요. |
| onAfterLeave | Function |
Transition의 leave 애니메이션이 실행된 뒤에 발생하는 콜백이에요. |
| onClose | () => boolean | Promise<boolean> |
알림이 닫힐 때의 콜백이에요. false를 반환하거나, promise가 false로 resolve되거나 reject되면 이 닫힘이 취소돼요. |
| onLeave | Function |
Transition의 leave 애니메이션이 실행될 때 발생하는 콜백이에요. |
NotificationReactive Methods
| 이름 | 타입 | 설명 |
|---|---|---|
| destroy | () |
알림을 제거해요. |
더 알아보기 (Learn more)
짧고 가벼운 피드백은 Message 컴포넌트가, 화면을 가리는 확인 창은 Dialog가 더 잘 맞아요. 세 컴포넌트의 차이를 비교해 보면 선택이 쉬워져요.