首页 > 其他分享 >VUE3使用Vue-Toastification

VUE3使用Vue-Toastification

时间:2022-11-23 18:24:04浏览次数:69  
标签:vue false Toastification toastification 报警 Vue VUE3 import const

官方地址:https://vue-toastification.maronato.dev/?from=madewith.cn

需求:

要搞一个实时提醒弹窗,刚开始用的element plus里的Notification,但后面原型图又改了,加上了交互

 

 

 element plus 这时候就显得很鸡肋了,而且他的自定义html只支持原生,做个点击功能都费劲,这时候是祭出杀器Toastification了

 

他可以支持组建直接引入

 

 

 

 自定义内容在component里写就好了,然后在用的页面直接引入就行。

 

安装: 

npm install --save vue-toastification@next

main.js里引入

import 'vue-toastification/dist/index.css'

使用页面引入

import { useToast } from 'vue-toastification'

const toast = useToast();
toast.error({
        component: AlarmInfoDialog,
        listeners: {
            showDialog: () => alarmDetail.value.open()
        }
    }, {
        position: voiceParams.remindposition ?? 'bottom-left', //出现位置
        timeout: 6000, // 延时关闭时间
        closeOnClick: false, // 单击即关闭
        pauseOnFocusLoss: true,
        pauseOnHover: true, // 鼠标移入暂停
        draggable: false, // 允许通过拖动和滑动事件关闭
        draggablePercent: 0.6,
        showCloseButtonOnHover: false,
        hideProgressBar: false, // 显示/隐藏进度条
        closeButton: false,
        icon: false,
        rtl: false
    });

options具体设置在 另一篇文章中

css样式:

.Vue-Toastification__toast{
    padding: 0 0 5px 0;
}

不调css会有边框。你写的内容被包着,而且还有自带的背景色,很难看

component组件

<template>
        <div class="alarmInfo" style="background: #ffffff;border-radius: 5px">
            <div class="top">
                <div class="leftInfo"></div>
                <div class="centerInfo">报警</div>
                <div class="rightInfo" >
                    <img src="../assets/imgs/alarmDialog/bianji.svg" @click="edit" alt="" width="30">
                    <img src="../assets/imgs/alarmDialog/fuzhi.svg" @click="copyToClipboard" alt="" width="30">
                    <img src="../assets/imgs/alarmDialog/duihao.svg" @click="edit" alt="" width="30">
                    <img src="../assets/imgs/alarmDialog/chahao.svg" @click="edit" alt="" width="30">
                </div>
            </div>
            <div class="content">
                <div class="info">
                    <div class="info-head">车牌号</div>
                    <span class="info-icon">:</span>
                    <div class="info-text">${waringInfoObj.carNo}</div>
                </div>
                <div class="info">
                    <div class="info-head">车辆颜色</div>
                    <span class="info-icon">:</span>
                    <div class="info-text">黄色</div>
                </div>
                <div class="info">
                    <div class="info-head">报警等级</div>
                    <span class="info-icon">:</span>
                    <div class="info-text">一级报警</div>
                </div>
                <div class="info">
                    <div class="info-head">报警类型</div>
                    <span class="info-icon">:</span>
                    <div class="info-text" style="color: crimson">超速报警 </div>
                </div>
                <div class="info">
                    <div class="info-head">报警详情</div>
                    <span class="info-icon">:</span>
                    <div class="info-text">超速报警</div>
                </div>
                <div class="info">
                    <div class="info-head">速度</div>
                    <span class="info-icon">:</span>
                    <div class="info-text">超速报警101km/h(超速时长:51秒)</div>
                </div>
                <div class="info">
                    <div class="info-head">限速</div>
                    <span class="info-icon">:</span>
                    <div class="info-text">60km/h</div>
                </div>
                <div class="info">
                    <div class="info-head">时间</div>
                    <span class="info-icon">:</span>
                    <div class="info-text">2022-08-01 12:15:00</div>
                </div>
                <div class="info">
                    <div class="info-head">驾驶员</div>
                    <span class="info-icon">:</span>
                    <div class="info-text">张三(15609199638)</div>
                </div>
                <div class="info">
                    <div class="info-head">报警位置</div>
                    <span class="info-icon">:</span>
                    <div class="info-text">四川省 成都市 简阳市 双桥子街道 成简快速路10米 大堰</div>
                </div>
            </div>
        </div>
</template>
<script setup>
import { defineExpose, defineEmits } from "vue";
import useClipboard from 'vue-clipboard3'
import { ElMessage } from "element-plus";

const { toClipboard } = useClipboard()
const emit = defineEmits(['showDialog'])

// 点击编辑按钮
const edit = () => {
    emit('showDialog')
}</script>

 

标签:vue,false,Toastification,toastification,报警,Vue,VUE3,import,const
From: https://www.cnblogs.com/alannero/p/16919352.html

相关文章

  • Vue遍历data中某个字段并累加,res.result.forEach方法总结
    forEach的定义和方法:forEach()方法用于调用数组的每个元素,并将元素传递给回调函数。注意:forEach()对于空数组是不会执行回调函数的。一、html部分<divclass="tab-con......
  • vue组件-文本超出显示点点点且悬浮可查看所有内容
    需求当文本超出的时候需要显示点点点,然后鼠标悬浮其上要能查看所有的文本内容。就直接封装一个通用的组件。依赖项element-plusvue3组件存放目录新建vue文件/compo......
  • Vue 初识
    官方地址地址:https://cn.vuejs.org/安装Vue库地址:https://v2.cn.vuejs.org/v2/guide/installation.html 安装浏览器调试工具 另外一种方式安装Vue-devtools......
  • vue2源码学习1
    1.vue源码解读流程newVue调用的是Vue.prototype._init从该函数开始经过$options参数合并之后initLifecycle初始化生命周期标志初始化事件,初始化渲染函数。......
  • java web开发(和vue联合开发)
        前面我们谈到了很多次vue,也说到了vue的很多优点。比如说,vue实现了mvc中全部v的功能,也就是view的部分。这样,后端开发就变得很简单,前后端之间只要实现json数据的......
  • element ui框架(vuex3使用)
        前面我们使用了sessionStorage实现了登陆状态的保存。但是sessionStorage保存的数据是有限的,如果希望实现vue不同组件之间的数据共享,可以使用vuex来实现。目前......
  • element ui框架(vuex模块化)
        上一节我们说到了vuex在数据保存中的作用。其实vuex在实际使用中,需要保存非常多的数据,不可能所有的数据都放到index.js里面。因此,有必要把数据放到单独的模块里......
  • 前端-Avue属性解释
    Avue属性<template><!--基础组件--><basic-container><!--<el-button@click='exportHandle'>导出</el-button>--><avue-crud设置表格属性......
  • Vue项目网页报错Cannot read property ‘components‘ of undefined
    Vue项目网页报错Cannotreadproperty‘components‘ofundefined   记录一下项目中出现的这个报错,这个报错的原因是在App.vue中导入的组件中重复引用了同一个文......
  • vue脚手架安装及依赖
    一、安装VueCil(脚手架)需要先安装node.js,这是node官网地址:https://nodejs.org/en/download/,node有两种版本一种是稳定版一种开发版安装完成输入node-v查......