网站首页 > 技术文章 正文
今天给小伙伴们推荐一款轻量级的小巧精致的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
好了,就分享到这里。希望对大家有些些帮助。喜欢的话,多支持一下!
猜你喜欢
- 2024-09-10 一个基于vite构建的vue3+pinia+ts+element初始化开箱即用的项目
- 2024-09-10 GitHub一篇《Vue 加载远程组件解决方案》,引起业内大佬点评
- 2024-09-10 页面刷新时vuex数据持久化问题的解决方案:第三方插件完美实现
- 2024-09-10 基于vite + Vue3 + element-plus的前后端分离基础项目搭建
- 2024-09-10 Vue导入模块import xxx from '@/xxx'中的@是什么含义?
- 2024-09-10 终于搞懂了!原来 Vue 3 的 generate 是这样生成 render 函数的
- 2024-09-10 Vue3 + TS 中使用 Provide/Inject 需要考虑的三大问题
- 2024-09-10 关于Vue3的setup attribute标识是否是一个值得使用的语法糖?
- 2024-09-10 聊一聊如何在Vue中使用事件总线( Event Bus)进行组件间通信
- 2024-09-10 vite+vue3实现网页版编辑器,带高亮以及代码提
- 02-21走进git时代, 你该怎么玩?_gits
- 02-21GitHub是什么?它可不仅仅是云中的Git版本控制器
- 02-21Git常用操作总结_git基本用法
- 02-21为什么互联网巨头使用Git而放弃SVN?(含核心命令与原理)
- 02-21Git 高级用法,喜欢就拿去用_git基本用法
- 02-21Git常用命令和Git团队使用规范指南
- 02-21总结几个常用的Git命令的使用方法
- 02-21Git工作原理和常用指令_git原理详解
- 最近发表
- 标签列表
-
- cmd/c (57)
- c++中::是什么意思 (57)
- sqlset (59)
- ps可以打开pdf格式吗 (58)
- phprequire_once (61)
- localstorage.removeitem (74)
- routermode (59)
- vector线程安全吗 (70)
- & (66)
- java (73)
- org.redisson (64)
- log.warn (60)
- cannotinstantiatethetype (62)
- js数组插入 (83)
- resttemplateokhttp (59)
- gormwherein (64)
- linux删除一个文件夹 (65)
- mac安装java (72)
- reader.onload (61)
- outofmemoryerror是什么意思 (64)
- flask文件上传 (63)
- eacces (67)
- 查看mysql是否启动 (70)
- java是值传递还是引用传递 (58)
- 无效的列索引 (74)