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

Toast — 가벼운 알림

원문 보기 위키 갱신

화면에 짧게 떴다가 사라지는 가벼운 알림 메시지예요. 텍스트, 성공·실패·경고 아이콘, 로딩 표시 등 다양한 형태를 함수 호출 한 줄로 띄울 수 있어요.

출처: Toast — doc.en-US.md

본문

가벼운 알림(토스트)용이에요.

설치

import { createApp } from 'vue'
import { Toast } from '@nutui/nutui'

const app = createApp()
app.use(Toast)

텍스트

:::demo

<template>
  <nut-cell title="Text" is-link @click="textToast('text message~')"></nut-cell>
</template>
<script setup>
import { showToast } from '@nutui/nutui'
const textToast = (msg) => {
  showToast.text(msg)
}
</script>

:::

제목

:::demo

<template>
  <nut-cell title="Toast Title" is-link @click="textToast('title message~')"></nut-cell>
</template>
<script setup>
import { showToast } from '@nutui/nutui'
const textToast = (msg) => {
  showToast.text(msg, {
    title: 'Toast Title'
  })
}
</script>

:::

성공

:::demo

<template>
  <nut-cell title="Toast Success" is-link @click="textToast('Success')"></nut-cell>
</template>
<script setup>
import { showToast } from '@nutui/nutui'
const textToast = (msg) => {
  showToast.success(msg)
}
</script>

:::

실패

:::demo

<template>
  <nut-cell title="Toast Fail" is-link @click="textToast('Fail')"></nut-cell>
</template>
<script setup>
import { showToast } from '@nutui/nutui'
const textToast = (msg) => {
  showToast.fail(msg)
}
</script>

:::

경고

:::demo

<template>
  <nut-cell title="Toast Warn" is-link @click="textToast('Warn')"></nut-cell>
</template>
<script setup>
import { showToast } from '@nutui/nutui'
const textToast = (msg) => {
  showToast.warn(msg)
}
</script>

:::

로딩

:::demo

<template>
  <nut-cell title="Toast Loading" is-link @click="textToast('Loading')"></nut-cell>
</template>
<script setup>
import { showToast } from '@nutui/nutui'
const textToast = (msg) => {
  showToast.loading(msg)
}
</script>

:::

사라지지 않게 하기

:::demo

<template>
  <nut-cell title="Toast Not Disappear" is-link @click="textToast('Toast Not Disappear')"></nut-cell>
</template>
<script setup>
import { showToast } from '@nutui/nutui'
const textToast = (msg) => {
  showToast.text(msg, {
    duration: 0
  })
}
</script>

:::

하단 위치 높이 커스터마이즈

:::demo

<template>
  <nut-cell title="Custom Bottom Height" is-link @click="textToast('Custom Bottom Height')"></nut-cell>
</template>
<script setup>
import { showToast } from '@nutui/nutui'
const textToast = (msg) => {
  showToast.text(msg, {
    center: false,
    bottom: '10%'
  })
}
</script>

:::

반투명 커버가 있는 로딩

:::demo

<template>
  <nut-cell title="Loading with transparent cover" is-link @click="textToast('Loading')"></nut-cell>
</template>
<script setup>
import { showToast } from '@nutui/nutui'
const textToast = (msg) => {
  showToast.loading(msg, {
    cover: true
  })
}
</script>

:::

JS 모듈에서 import해서 사용

import { showToast } from '@nutui/nutui'
showToast.text('use in js module')
// Return the instance, you can manually call the hide method in the instance to close the prompt
const toast = showToast.loading('use in js module')
toast.hide()

API

Methods

Methods Description Attribute Return value
showToast.text Show text toast message | options toast instance(message support incoming HTML)
showToast.success Show success toast message | options toast instance
showToast.fail Show fail toast message | options toast instance
showToast.warn Show warn toast message | options toast instance
showToast.hide Close toast clearAll: boolean void
showToast.loading Show loading toast message | options toast instance

ToastOptions

字段 说明 类型 默认值
id Identifier, share one instance at the same time, default to multiple instances string | number -
duration Toast duration(ms), won't disappear if value is 0 number 2000
title title string -
center Whether to display in the middle of the page (display at the bottom when false) boolean true
bottom The distance from the bottom of the page (px or %), which takes effect when option.center is false string 30px
text-align-center Whether the multi-line copy is centered boolean true
bgColor background color (transparency) string rgba(0, 0, 0, 0.8)
custom-class Custom Class string -
icon Custom Icon Component -
size Text Size small/base/large string base
cover Whether to show the mask layer boolean false
cover-color Cover Color string rgba(0,0,0,0)
loading-rotate Whether the loading icon is rotated, only valid for the loading type boolean true
close Callback function after close function null
close-on-click-overlay Whether to close when overlay is clicked boolean false
custom-class Custom Class string -

테마 (Theming)

CSS 변수

이 컴포넌트는 스타일을 커스터마이징할 때 쓸 수 있는 CSS 변수를 제공해요. 자세한 내용은 ConfigProvider 컴포넌트 문서를 참고하세요.

Name Default Value
--nut-toast-title-font-size 16px
--nut-toast-text-font-size 14px
--nut-toast-font-color var(--nut-white)
--nut-toast-inner-padding 24px 30px
--nut-toast-inner-bg-color rgba(0, 0, 0, 0.8)
--nut-toast-inner-border-radius 12px
--nut-toast-cover-bg-color rgba(0, 0, 0, 0)

더 알아보기 (Learn more)

이 문서는 NutUI v4 공식 영문 문서를 한국어로 옮긴 글이에요. 최신 API와 변경 사항은 원문에서 확인하는 게 가장 정확해요.