VuePress完美整合Toast消息提示

VuePress 整合 Vue-Toastification 插件笔记

记录如何在 VuePress 项目中整合使用 vue-toastification 插件,实现优雅的消息提示。

一、安装依赖

bash 复制代码
npm install vue-toastification

或者使用 yarn:

bash 复制代码
yarn add vue-toastification

二、配置 VuePress 客户端增强文件

在 VuePress 项目的 .vuepress 目录下创建或编辑 enhanceApp.js 文件:

ts 复制代码
// 引入 Toast 插件和样式
import Toast from "vue-toastification";
import "vue-toastification/dist/index.css";

export default ({ Vue }) => {
  // 全局注册组件
  Vue.component('MyGlobalComponent', MyGlobalComponent);
  // 注册 Toast 插件
  Vue.use(Toast, {
    // 可选的配置项
    position: "top-right",
    timeout: 10000,
    closeOnClick: true,
    pauseOnHover: true,
  });
}

三、页面中使用示例

在任意 .vue 文件或 Markdown 文件中使用时,可以通过 this.$toast 调用提示:

vue 复制代码
<template>
  <button @click="showToast">点击提示</button>
</template>

<script>
function showToast() {
  this.$toast('xxx')
  this.$toast.success('xxx')
  this.$toast.info('xxx');
  this.$toast.warning('xxx');
  this.$toast.error('xxx');
}
</script>

通过以上配置 并使用 vue-toastification,我们可以轻松地为 VuePress 项目添加友好的通知提示功能,适用于各种用户交互场景,如表单提交、请求成功或错误提示等。


如果你需要更复杂的用法,比如自定义样式、不同类型的提示,可以参考

官方GitHub:点我前往

相关推荐
蒲公英源码3 分钟前
基于PHP+Vue+小程序快递比价寄件系统
vue.js·小程序·php
How_doyou_do14 分钟前
模态框的两种管理思路
java·服务器·前端
snow@li38 分钟前
前端:前端/浏览器 可以录屏吗 / 实践 / 录制 Microsoft Edge 标签页、应用窗口、整个屏幕
前端·浏览器录屏·前端录屏·web录屏
李贺梖梖44 分钟前
CSS学习
前端·css
蚂小蚁1 小时前
一文吃透:宏任务、微任务、事件循环、浏览器渲染、Vue 批处理与 Node 差异(含性能优化)
前端·面试·架构
狼性书生1 小时前
uniapp实现的Tab 选项卡组件模板
前端·uni-app·vue·组件·插件
吃饺子不吃馅1 小时前
前端画布类型编辑器项目,历史记录技术方案调研
前端·架构·github
许___1 小时前
el-table多选模式下跨分页保留当前页选项
javascript·vue.js
拜晨1 小时前
使用motion实现小宇宙贴纸墙效果
前端·交互设计