[](https://www.npmjs.com/package/@kyvg/vue3-notification)

## Upgrade to v3.x
### Breaking changes
- `title` and `text` no longer render with [`v-html`](https://vuejs.org/api/built-in-directives.html#v-html). Use `dangerouslySetInnerHtml` prop to render `title` and `text` with [`v-html`](https://vuejs.org/api/built-in-directives.html#v-html)
# Vue.js notifications
This is a fork and port of Vue 2 [vue-notifications](https://github.com/euvl/vue-notification) created by [euvl](https://github.com/euvl) to now support Vue 3. If you're using Vue 2.x use his version.
<p align="center">
<img src="https://media.giphy.com/media/xUn3C6FmbGmszMem64/giphy.gif">
</p>
## Setup
```bash
npm install --save @kyvg/vue3-notification
yarn add @kyvg/vue3-notification
```
Add dependencies to your `main.js`:
```javascript
import { createApp } from 'vue'
import Notifications from '@kyvg/vue3-notification'
const app = createApp({...})
app.use(Notifications)
```
Add the global component to your `App.vue`:
```vue
<notifications />
```
Please note that this library does not inherently support Nuxt 3. To enable compatibility with Nuxt 3, use the [`nuxt3-notifications`](https://github.com/windx-foobar/nuxt3-notifications) wrapper
## Usage
Trigger notifications from your `.vue` files:
```javascript
// simple
this.$notify("Hello user!");
// using options
this.$notify({
title: "Important message",
text: "Hello user!",
});
```
Or trigger notifications from other files, for example, your router:
```javascript
import { notify } from "@kyvg/vue3-notification";
notify({
title: "Authorization",
text: "You have been logged in!",
});
```
Or use Composition API style:
```javascript
import { useNotification } from "@kyvg/vue3-notification";
const { notify } = useNotification()
notify({
title: "Authorization",
text: "You have been logged in!",
});
```
### Migration
#### Vue 2.x syntax
```javascript
Vue.notify({
title: "Vue 2 notification",
});
```
#### Vue 3.x syntax
```javascript
import { notify } from "@kyvg/vue3-notification";
notify({
title: "Vue 3 notification ð",
});
```
#### Vue 3.x Composition API syntax
```javascript
import { useNotification } from "@kyvg/vue3-notification";
const notification = useNotification()
notification.notify({
title: "Vue 3 notification ð",
});
```
Also you can use [destructuring assignment](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment)
```javascript
import { useNotification } from "@kyvg/vue3-notification";
const { notify } = useNotification()
notify({
title: "Vue 3 notification ð",
});
```
### Component props
The majority of settings for the Notifications component are configured using props:
```vue
<notifications position="bottom right" classes="my-custom-class" />
```
Note that all props are optional.
| Name | Type | Default | Description |
| ---------------- | ------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------- |
| position | String/Array | 'top right' | Part of the screen where notifications will pop out |
| width | Number/String | 300 | Width of notification holder, can be `%`, `px` string or number.<br>Valid values: '100%', '200px', 200 |
| classes | String/Array | 'vue-notification' | List of classes that will be applied to notification element |
| group | String | null | Name of the notification holder, if specified |
| duration | Number | 3000 | Time (in ms) to keep the notification on screen (if **negative** - notification will stay **forever** or until clicked) |
| speed | Number | 300 | Time (in ms) to show / hide notifications |
| animation-type | String | 'css' | Type of animation, currently supported types are `css` and `velocity` |
| animation-name | String | null | Animation name required for `css` animation |
| animation | Object | Custom | Animation configuration for [Velocity](#Animation]) animation |
| max | Number | Infinity | Maximum number of notifications that can be shown in notification holder |
| reverse | Boolean | false | Show notifications in reverse order |
| ignoreDuplicates | Boolean | false | Ignore repeated instances of the same notification |
| closeOnClick | Boolean | true | Close notification when clicked |
| pauseOnHover | Boolean | false | Keep the notification open while mouse hovers on notification |
| dangerouslySetInnerHtml | Boolean | false | Use [v-html](https://vuejs.org/api/built-in-directives.html#v-html) to set `title` and `text` |
### Component events
| Name | Type | Description |
| ---------------- | -------------------------------- | -------------------------------------------- |
| click | (item: NotificationItem) => void | The callback function that is triggered when notification was clicked
| destroy | (item: NotificationItem) => void | The callback function that is triggered when notification was destroyes
| start | (item: NotificationItem) => void | The callback function that is triggered when notification was appeared
### API
Notifications are triggered via the API:
```javascript
this.$notify({
// (optional)
// Name of the notification holder
group: 'foo',
// (optional)
// Title (will be wrapped in div.notification-title)
title: 'This is the <em>title</em>',
// Content (will be wrapped in div.notification-content)
text: 'This is some <b>content</b>',
// (optional)
// Class that will be assigned to the notification
type: 'warn',
// (optional, override)
// Time (in ms) to keep the notification on screen
duration: 10000,
// (optional, override)
// Time (in ms) to show / hide notifications
speed: 1000
// (optional)
// Data object that can be used in your template
data: {}
})
```
To remove notifications, include the `clean: true` parameter.
```javascript
this.$notify({
group: "foo", // clean only the foo group
clean: true,
});
```
### Plugin Options
Configure the plugin itself using an additional options object:
```js
app.use(Notifications, { name: "alert" });
```
All options are optional:
| Name | Type | Default | Description |
| ------------- | ---
没有合适的资源?快使用搜索试试~ 我知道了~
Vue 3 通知库.zip

共56个文件
ts:20个
md:10个
js:6个

1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 145 浏览量
2024-12-01
22:51:26
上传
评论
收藏 106KB ZIP 举报
温馨提示
Vue 3 通知库 升级到 v3.x重大变更title并且text不再使用 进行渲染v-html。使用dangerouslySetInnerHtmlprop 进行渲染title并text使用v-htmlVue.js 通知这是euvl创建的Vue 2 vue-notifications的一个分支和端口,现在支持 Vue 3。如果您使用的是 Vue 2.x,请使用他的版本。设置npm install --save @kyvg/vue3-notificationyarn add @kyvg/vue3-notification添加依赖项到您的main.jsimport { createApp } from 'vue'import Notifications from '@kyvg/vue3-notification'const app = createApp({...})app.use(Notifications)将全局组件添加到您的App.vue<notifications />请注意,此库本身不支持 Nuxt 3。要实现与 Nuxt 3
资源推荐
资源详情
资源评论






























收起资源包目录













































































共 56 条
- 1
资源评论


徐浪老师
- 粉丝: 9536
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- [四川]农业综合开发项目水利工程施工组织设计.docx
- 聘请外籍工作人员合同.doc
- 主题活动:“口罩”知多少.doc
- 单位(子单位)工程安全和功能检验.doc
- 自助银行装修改造工程施工组织设计.doc
- 播音发声-共鸣控制.doc
- 海风小店,开源商城,微信小程序商城管理后台,后台管理,VUE.zip
- 国有建设单位会计制度补充规定.doc
- 白涛隧道工程保险招标文件.doc
- 微信小程序:周公解梦境.zip
- 水电站二期导流设计说明.doc
- 地下聚氨酯涂膜防水工程.doc
- 化工矿业“十二五”发展规划》[2011-8-11].docx
- 微信小程序-餐饮点餐外卖-开箱即用.zip
- chatgpt微信聊天小程序。java编写服务器,实现chatgpt接口的调用,微信小程序用于聊天。二者基于webSoc
- 8-第八章-歌剧院钢结构安装.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
