Notify
Notify (알림)
페이지 상단에 메시지 팁을 띄워 사용자에게 상태를 알려 주는 컴포넌트예요. 함수 호출로 간단히 띄울 수도 있고, 템플릿에서 nut-notify 컴포넌트로 직접 제어할 수도 있어요.
출처: 문서
본문
소개 (Intro)
페이지 상단에 메시지 팁을 표시해요.
설치 (Install)
import { createApp } from 'vue'
import { Notify } from '@nutui/nutui'
const app = createApp()
app.use(Notify)
기본 사용법 (Basic Usage)
:::demo
<template>
<nut-cell is-Link @click="baseNotify('Basic Usage')">Basic Usage</nut-cell>
</template>
<script setup>
import { ref } from 'vue'
import { showNotify } from '@nutui/nutui'
import '@nutui/nutui/dist/packages/notify/style'
const baseNotify = (msg) => {
showNotify.text(msg, {
onClose: () => {
console.log('close')
},
onClick: () => {
console.log('click')
}
})
}
</script>
:::
Notify 타입 (Notify Type)
<template>
<nut-cell-group title="Notify Type">
<nut-cell is-Link @click="primaryNotify('Primary Notify')">Primary Notify</nut-cell>
<nut-cell is-Link @click="successNotify('Success Notify')">Success Notify</nut-cell>
<nut-cell is-Link @click="errorNotify('Error Notify')">Error Notify</nut-cell>
<nut-cell is-Link @click="warningNotify('Warning Notify')">Warning Notify</nut-cell>
</nut-cell-group>
</template>
<script setup>
import { ref } from 'vue'
import { showNotify } from '@nutui/nutui'
import '@nutui/nutui/dist/packages/notify/style'
const primaryNotify = (msg) => {
showNotify.primary(msg)
}
const successNotify = (msg) => {
showNotify.success(msg)
}
const errorNotify = (msg) => {
showNotify.danger(msg)
}
const warningNotify = (msg) => {
showNotify.warn(msg)
}
</script>
showNotify에는 primary success danger warn 메서드가 준비되어 있어서, 상황에 맞는 타입을 골라 호출하면 돼요.
커스텀 (Custom)
<template>
<nut-cell-group title="Custom Style">
<nut-cell is-Link @click="cusBgNotify('Customize background and font colors')"
>Customize background and font colors</nut-cell
>
</nut-cell-group>
<nut-cell-group title="Custom Duration">
<nut-cell is-Link @click="timeNotify('Custom Duration')">Custom Duration</nut-cell>
</nut-cell-group>
<nut-cell-group title="Custom Postion">
<nut-cell is-Link @click="positionNotify('Custom Postion')">Custom Postion</nut-cell>
</nut-cell-group>
</template>
<script setup>
import { ref } from 'vue'
import { showNotify } from '@nutui/nutui'
import '@nutui/nutui/dist/packages/notify/style'
const cusBgNotify = (msg) => {
showNotify.text(msg, { color: '#ad0000', background: '#ffe1e1' })
}
const timeNotify = (msg) => {
showNotify.text(msg, { duration: 10000 })
}
const positionNotify = (msg) => {
showNotify.text(msg, { position: 'bottom' })
}
</script>
색상·표시 시간·위치를 옵션으로 바꿀 수 있어요. duration에 0을 주면 알림이 사라지지 않는다는 점도 기억해 두면 좋아요.
템플릿에서 사용 (Template use)
<template>
<nut-cell-group title="Template use">
<nut-cell is-Link @click="onClick">Template use</nut-cell>
<nut-notify v-model:visible="show" :duration="2000">
<span>Content</span>
</nut-notify>
</nut-cell-group>
</template>
<script setup>
import { ref } from 'vue'
import { showNotify } from '@nutui/nutui'
import '@nutui/nutui/dist/packages/notify/style'
const show = ref(false)
const onClick = () => {
show.value = true
}
</script>
API
Props
| Attribute | Description | Type | Default |
|---|---|---|---|
| type | The information type of the prompt, the optional values are primary success danger warning |
string | danger |
| visible | Display or not | boolean | false |
| msg | Display content, support line feed through \n |
string | '' |
| duration | Display duration (ms),value is 0 ,notify not disappear | number | 3000 |
| color | Font Color | string | - |
| background | Background color | string | - |
| class-name | Custom class name | string | number | 1 |
| position | custom position, optional values are top bottom left right center |
string | top |
Events
| Event | Description | Arguments |
|---|---|---|
| click | Emitted when notify is clicked | - |
| closed | Emitted when notify is closed | - |
Theming
CSS Variables
The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.
| Name | Default Value |
|---|---|
| --nut-notify-text-color | var(--nut-white) |
| --nut-notify-padding | 12px 0 |
| --nut-notify-font-size | 14px |
| --nut-notify-height | 44px |
| --nut-notify-line-height | auto |
| --nut-notify-base-background-color | linear-gradient(135deg,var(--nut-primary-color) 0%,var(--nut-primary-color-end) 100%) |
| --nut-notify-primary-background-color | linear-gradient(315deg, rgba(73, 143, 242, 1) 0%, rgba(73, 101, 242, 1) 100%) |
| --nut-notify-success-background-color | linear-gradient(135deg,rgba(38, 191, 38, 1) 0%,rgba(39, 197, 48, 1) 45%,rgba(40, 207, 63, 1) 83%,rgba(41, 212, 70, 1) 100%) |
| --nut-notify-danger-background-color | rgba(250, 50, 25, 1) |
| --nut-notify-warning-background-color | linear-gradient(135deg, rgba(255, 93, 13, 1) 0%, rgba(255, 154, 13, 1) 100%) |
더 알아보기 (Learn more)
- 원문 문서: Notify — NutUI v4 영문 문서
- NutUI 저장소: jd-opensource/nutui