본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Dialog

원문 보기 위키 갱신

Dialog는 사용자의 확인이 필요한 작업 앞에서 메시지를 띄우는 컴포넌트예요. 명령형 API(useDialog)로 원하는 시점에 대화상자를 열 수 있고, 컴포넌트 형태로 선언적으로 쓸 수도 있죠. 행동하기 전에 확인을 요구하는 자리에서 자연스럽게 쓰여요.

출처: 문서

본문

행동하기 전에, 확인을 먼저 해요.

dialog를 사용하려면 관련 메서드를 호출하는 컴포넌트를 n-dialog-provider로 감싸고, useDialog로 API를 가져와야 해요.

예를 들면 다음과 같아요:

<!-- App.vue -->
<n-dialog-provider>
  <content />
</n-dialog-provider>
import { useDialog } from 'naive-ui'
import { defineComponent } from 'vue'

// content
export default defineComponent({
  setup() {
    const dialog = useDialog()
    return {
      warning() {
        dialog.warning(options)
      }
    }
  }
})

Demos

basic.vue
async.vue
use-component.vue
mask.vue
action.vue
use-dialog-reactive-list.vue

API

useDialog API

이름 타입 설명
destroyAll () => void 열려 있는 모든 dialog를 닫아요.
create (options: DialogOptions) => DialogReactive dialog를 만들어요.
error (options: DialogOptions) => DialogReactive error 타입 dialog를 사용해요.
info (options: DialogOptions) => DialogReactive info 타입 dialog를 사용해요.
success (options: DialogOptions) => DialogReactive success 타입 dialog를 사용해요.
warning (options: DialogOptions) => DialogReactive warning 타입 dialog를 사용해요.

useDialogReactiveList API

() => Ref<readonly DialogReactive[]>

DialogOptions Properties

이름 타입 기본값 설명 버전
action () => VNodeChild undefined 조작 영역의 콘텐츠예요. 렌더 함수여야 해요.
actionClass string undefined 조작 영역의 클래스 이름이에요. 2.38.2
actionStyle Object | string undefined 조작 영역의 스타일이에요. 2.38.2
autoFocus boolean true modal 안에서 첫 번째 포커스 가능한 요소에 포커스를 줄지 여부예요. 2.28.3
blockScroll boolean true 활성화됐을 때 body 스크롤을 막을지 여부예요. 2.28.3
bordered boolean false border를 표시할지 여부예요.
class any undefined dialog의 클래스 이름이에요. 2.33.0
closable boolean true close 아이콘을 표시할지 여부예요.
closeFocusable boolean false 닫기 버튼에 포커스를 줄 수 있는지 여부예요. 2.43.0
closeOnEsc boolean true Esc 키를 눌렀을 때 dialog를 닫을지 여부예요. 2.26.4
content string | (() => VNodeChild) undefined 콘텐츠예요. 렌더 함수일 수 있어요.
contentClass string undefined 콘텐츠의 클래스 이름이에요. 2.38.2
contentStyle Object | string undefined 콘텐츠의 스타일이에요. 2.38.2
draggable boolean | { bounds?: 'none' } false 드래그할 수 있는지 여부예요. 2.41.0
iconPlacement 'left' | 'top' 'left' 아이콘의 위치예요.
icon () => VNodeChild undefined icon의 Render 함수예요.
loading boolean false loading 상태를 표시할지 여부예요.
maskClosable boolean true mask를 클릭해서 dialog를 닫을 수 있는지 여부예요.
negativeButtonProps ButtonProps undefined 취소 버튼의 DOM props예요. 2.27.0
negativeText string undefined 취소 버튼 텍스트예요. 설정하지 않으면 해당 버튼은 표시되지 않아요.
positiveButtonProps ButtonProps undefined 확인 버튼의 DOM props예요. 2.27.0
positiveText string undefined 확인 버튼 텍스트예요. 설정하지 않으면 해당 버튼은 표시되지 않아요.
showIcon boolean true icon을 표시할지 여부예요.
style string | Object undefined dialog의 스타일이에요.
title string | (() => VNodeChild) undefined 제목이에요. 렌더 함수일 수 있어요.
titleClass string undefined 콘텐츠의 클래스 이름이에요. 2.38.2
titleStyle Object | string undefined 콘텐츠의 스타일이에요. 2.38.2
transformOrigin 'mouse' | 'center' 'mouse' dialog 표시 애니메이션의 transform origin이에요. 2.34.0
type 'error | 'success' | 'warning' 'warning' dialog의 타입이에요.
zIndex number undefined dialog의 z index예요. 2.43.0
onAfterEnter () => void undefined enter 애니메이션이 끝날 때의 콜백이에요. 2.33.0
onAfterLeave () => void undefined leave 애니메이션이 끝날 때의 콜백이에요. 2.33.3
onClose () => boolean | Promise<boolean> | any undefined 기본 동작은 확인을 닫는 거예요. false를 반환하거나 false로 이행하거나 Promise rejected이면 기본 동작이 막혀요.
onNegativeClick (e: MouseEvent) => boolean | Promise<boolean> | any undefined 기본 동작은 확인을 닫는 거예요. false를 반환하거나 false로 이행하거나 Promise rejected이면 기본 동작이 막혀요.
onPositiveClick (e: MouseEvent) => boolean | Promise<boolean> | any undefined 기본 동작은 확인을 닫는 거예요. false를 반환하거나 false로 이행하거나 Promise rejected이면 기본 동작이 막혀요.
onMaskClick () => void undefined mask를 클릭했을 때 트리거되는 콜백이에요.

DialogReactive API

DialogReactive Properties

모든 속성은 동적으로 수정할 수 있어요.

이름 타입 설명 버전
actionClass string 조작 영역의 클래스 이름이에요. 2.38.2
actionStyle Object | string 조작 영역의 스타일이에요. 2.38.2
bordered boolean border를 표시할지 여부예요.
class any dialog의 클래스 이름이에요. 2.33.0
closable boolean close 아이콘을 표시할지 여부예요.
closeFocusable boolean 닫기 버튼에 포커스를 줄 수 있는지 여부예요. 2.43.0
closeOnEsc boolean Esc 키를 눌렀을 때 dialog를 닫을지 여부예요. 2.26.4
content string | (() => VNodeChild) 콘텐츠예요. 렌더 함수일 수 있어요.
contentClass string 콘텐츠의 클래스 이름이에요. 2.38.2
contentStyle Object | string 콘텐츠의 스타일이에요. 2.38.2
iconPlacement 'left' | 'top' 아이콘의 위치예요.
icon () => VNodeChild icon의 Render 함수예요.
loading boolean loading 상태를 표시할지 여부예요.
maskClosable boolean mask를 클릭해서 dialog를 닫을 수 있는지 여부예요.
negativeButtonProps ButtonProps 취소 버튼의 DOM props예요. 2.27.0
negativeText string 설정하지 않으면 해당 버튼은 표시되지 않아요.
positiveButtonProps ButtonProps 확인 버튼의 DOM props예요. 2.27.0
positiveText string 설정하지 않으면 해당 버튼은 표시되지 않아요.
show-icon boolean icon을 표시할지 여부예요.
style string | Object dialog의 스타일이에요.
title string | (() => VNodeChild) 렌더 함수일 수 있어요.
titleClass string 콘텐츠의 클래스 이름이에요. 2.38.2
titleStyle Object | string 콘텐츠의 스타일이에요. 2.38.2
transformOrigin 'mouse' | 'center' dialog 표시 애니메이션의 transform origin이에요. 2.34.0
type 'error | 'success' | 'warning' dialog의 타입이에요.
onAfterEnter () => void | undefined enter 애니메이션이 끝날 때의 콜백이에요. 2.33.0
onAfterLeave () => void | undefined leave 애니메이션이 끝날 때의 콜백이에요. 2.33.3
onClose () => boolean | Promise<boolean> | any 기본 동작은 확인을 닫는 거예요. false를 반환하거나 resolve false 또는 Promise rejected이면 기본 동작이 막혀요.
onEsc () => void Esc 키를 누르고 포커스가 dialog 안에 있을 때 발생하는 콜백이에요. 2.32.0
onNegativeClick (e: MouseEvent) => boolean | Promise<boolean> | any 기본 동작은 확인을 닫는 거예요. false를 반환하거나 resolve false 또는 Promise rejected이면 기본 동작이 막혀요.
onPositiveClick (e: MouseEvent) => boolean | Promise<boolean> | any 기본 동작은 확인을 닫는 거예요. false를 반환하거나 resolve false 또는 Promise rejected이면 기본 동작이 막혀요.

DialogReactive Methods

이름 타입 설명
destroy () dialog를 닫아요.

Dialog Props

이름 타입 기본값 설명 버전
action-class string undefined 조작 영역의 클래스 이름이에요. 2.38.2
action-style Object | string undefined 조작 영역의 스타일이에요. 2.38.2
bordered boolean false border를 표시할지 여부예요.
closable boolean true close 아이콘을 표시할지 여부예요.
close-focusable boolean false 닫기 버튼에 포커스를 줄 수 있는지 여부예요. 2.43.0
content string | (() => VNodeChild) undefined 렌더 함수일 수 있어요.
content-class string undefined 콘텐츠의 클래스 이름이에요. 2.38.2
content-style Object | string undefined 콘텐츠의 스타일이에요. 2.38.2
icon-placement 'left' | 'top' 'left' 아이콘의 위치예요.
icon () => VNodeChild undefined icon의 Render 함수예요.
loading boolean false loading 상태를 표시할지 여부예요.
negative-button-props ButtonProps undefined 취소 버튼의 DOM props예요. 2.27.0
negative-text string undefined 설정하지 않으면 해당 버튼은 표시되지 않아요.
positive-button-props ButtonProps undefined 확인 버튼의 DOM props예요. 2.27.0
positive-text string undefined 설정하지 않으면 해당 버튼은 표시되지 않아요.
show-icon boolean true icon을 표시할지 여부예요.
title string | (() => VNodeChild) undefined 제목이에요. 렌더 함수일 수 있어요.
title-class string undefined 콘텐츠의 클래스 이름이에요. 2.38.2
title-style Object | string undefined 콘텐츠의 스타일이에요. 2.38.2
type 'error | 'success' | 'warning' | 'info' 'warning' dialog의 타입이에요.
on-close () => void undefined 닫기 버튼을 클릭했을 때의 콜백이에요.
on-negative-click (e: MouseEvent) => void undefined positive 버튼을 클릭했을 때의 콜백이에요.
on-positive-click (e: MouseEvent) => void undefined negative 버튼을 클릭했을 때의 콜백이에요.

Dialog Slots

이름 파라미터 설명 버전
action () Action 콘텐츠.
default () dialog 콘텐츠.
header () Header 콘텐츠.
icon () Icon 콘텐츠.
close () Close 콘텐츠. 2.36.0

더 알아보기 (Learn more)

Dialog를 쓰려면 n-dialog-provider로 감싸는 전제 조건을 잊지 마세요. 열려 있는 dialog 목록을 반응형으로 다루고 싶으면 useDialogReactiveList와 해당 데모를 참고하세요.