# Notify
Notification component, used to display notification information at the top of the page.
## Basic Usage
You need to import this component in the page as a mounting point.
```html
```
```ts
import { useNotify } from '@/uni_modules/wot-design-uni'
const { showNotify, closeNotify } = useNotify()
// Automatically close after 3 seconds
showNotify('Notification content')
// Actively close
closeNotify()
```
## Notification Type
Supports four types of notifications: `primary`, `success`, `warning`, `danger`, with `danger` as the default.
```ts
// Primary notification
showNotify({ type: 'primary', message: 'Notification content' })
// Success notification
showNotify({ type: 'success', message: 'Notification content' })
// Danger notification
showNotify({ type: 'danger', message: 'Notification content' })
// Warning notification
showNotify({ type: 'warning', message: 'Notification content' })
```
## Custom Notification
```ts
showNotify({
message: 'Custom color',
color: '#ad0000',
background: '#ffe1e1'
})
showNotify({
message: 'Custom position',
position: 'bottom'
})
showNotify({
message: 'Custom duration',
duration: 1000
})
```
## Using Notify Component
If you need to embed components or other custom content in Notify, you can directly use the Notify component and customize it using the default slot.
```html
Call using Notify component
Success notification
```
```ts
import { ref, onMounted } from 'vue'
let timer: ReturnType
export default {
setup() {
const visible = ref(false)
const safeHeight = ref(0)
const showNotify = () => {
visible.value = true
if (timer) clearTimeout(timer)
timer = setTimeout(() => {
visible.value = false
}, 3000)
}
onMounted(() => {
// #ifdef H5
safeHeight.value = 44
// #endif
})
return {
visible,
showNotify,
safeHeight
}
}
}
```
## Advanced Demo
```vue
// App.vue
```
```vue
// /components/layout/layout.vue
```
```vue
// /pages/user.vue
User
Notification message
```
## Attributes
| Parameter | Description | Type | Accepted Values | Default | Version |
|-----------|-------------|------|-----------------|---------|----------|
| type | Type | NotifyType | `primary` `success` `warning` `danger` | `danger` | - |
| message | Display text, supports line breaks with `\n` | string | - | - | - |
| duration | Display duration (ms), when value is 0, notify will not disappear | number | - | `3000` | - |
| zIndex | Layer level | number | - | `99` | - |
| position | Pop-up position | NotifyPosition | `top` `bottom` | `top` | - |
| color | Font color | string | - | - | - |
| background | Background color | string | - | - | - |
| safeHeight | Top safe height | number / string | - | - | - |
| selector | Unique identifier | number | - | - | - |
| root-portal | Whether to detach from the page, used to solve various fixed positioning issues | boolean | - | false | 1.11.0 |
## Events
| Event Name | Description | Parameters | Version |
|------------|-------------|------------|----------|
| onClick | Triggered when clicking | event: MouseEvent | - |
| onOpened | Triggered when fully displayed | - | - |
| onClosed | Triggered when fully closed | - | - |