网站首页 > 精选文章 正文
今天给小伙伴们推荐一款轻量级的小巧精致的vue.js提示组件VueToastification。
vue-toastification 基于Vue的Toast通知提示组件。基于TS语法,易于定制,支持Nuxt、Composition API及Vue3。
安装
$ npm i vue-toastification -S
引入插件
import Vue from "vue";
import Toast from "vue-toastification";
import "vue-toastification/dist/index.css";
const options = {
// You can set your default options here
position: 'top-right', //显示位置
timeout: 3000, //关闭时间
pauseOnHover: true, //鼠标滑过停止
hideProgressBar: false, //隐藏关闭时间条
closeButton: false, //显示关闭按钮
... //更多配置
};
Vue.use(Toast, options);
使用
this.$toast("I'm a toast!");
this.$toast.info("Info toast");
this.$toast.success("Success toast");
this.$toast.error("Error toast");
this.$toast.warning("Warning toast");
// Or with options
this.$toast("My toast content", {
timeout: 2000,
... //更多配置
});
在 Composition API 中使用
Vue Toastification 同样也支持 Vue3.0 的 Composition API。
// App.vue
// Import from vue-toastification/composition, not vue-toastification
import { provideToast } from "vue-toastification/composition";
import "vue-toastification/dist/index.css";
setup() {
// Pass the Plugin Options here
provideToast({ timeout: 3000 });
// This is similar to `Vue.use(Toast)`, but will not register `$toast` to the Vue instance.
}
// MyComponent.vue
import { useToast } from "vue-toastification/composition";
setup() {
// Same interface as this.$toast
const toast = useToast();
const showToast = () => toast.success("I'm a toast!");
const clearToasts = () => toast.clear();
return { showToast, clearToasts };
}
渲染组件模板调用
// MyComponent.vue
<template>
<button @click="$emit('close-toast')">Close Toast</button>
</template>
// OtherFile.vue
import MyComponent from "./MyComponent.vue";
this.$toast(MyComponent);
渲染 JSX 组件调用
const myJSX = (
<div>
<h1>My Title</h1>
<span>My text</span>
</div>
);
this.$toast(myJSX);
附上项目示例及仓库地址
# 演示地址
https://maronato.github.io/vue-toastification/
# 项目地址
https://github.com/Maronato/vue-toastification
好了,就分享到这里。希望对大家有些些帮助。喜欢的话,多支持一下!
- 上一篇: Reaper控制器栏的魔法——JS系列脚本介绍
- 下一篇: Vue开发环境搭建
猜你喜欢
- 2025-05-27 vue3安装在线构建ckeditor5教程
- 2025-05-27 使用vue3和go搭建网站(附源码)
- 2025-05-27 「干货」Vue+Element前端导入导出Excel
- 2025-05-27 好的项目,万物皆可打包,我将Vue项目打包成客户端(模拟钉钉)
- 2025-05-27 vue下载excel文件方法
- 2025-05-27 vue组件的注册
- 2025-05-27 我常用的几个 VueUse 最佳组合,推荐给你们
- 2025-05-27 Vue开发环境搭建
- 最近发表
- 标签列表
-
- 向日葵无法连接服务器 (32)
- git.exe (33)
- vscode更新 (34)
- dev c (33)
- git ignore命令 (32)
- gitlab提交代码步骤 (37)
- java update (36)
- vue debug (34)
- vue blur (32)
- vscode导入vue项目 (33)
- vue chart (32)
- vue cms (32)
- 大雅数据库 (34)
- 技术迭代 (37)
- 同一局域网 (33)
- github拒绝连接 (33)
- vscode php插件 (32)
- vue注释快捷键 (32)
- linux ssr (33)
- 微端服务器 (35)
- 导航猫 (32)
- 获取当前时间年月日 (33)
- stp软件 (33)
- http下载文件 (33)
- linux bt下载 (33)