首页
新鲜事
留言
友情链接
搜索
1
自建RustDesk服务端笔记
342 阅读
2
解决低版本宝塔不识别php8以上版本
286 阅读
3
Typecho-Joe魔改记录
180 阅读
4
[Typecho小试牛刀]Joe主题增加文章目录(非插件方式)
170 阅读
5
一个php文件实现反代jsdelivr,并缓存文件到本地服务器
159 阅读
随手记
农信
代码
笔记
操作指南
农信人的自我修养
登录
搜索
标签搜索
Linux
shell
typecho
php
Joe
JS
python
matlab
论文写作
cdn
jsdelivr
git
PS
视频处理
远程桌面
pytorch
Windows
vue
浏览器
rustdesk
苏苏
公告:有问题可直接留言哦!
累计撰写
66
篇文章
累计收到
80
条评论
首页
栏目
随手记
农信
代码
笔记
操作指南
页面
新鲜事
留言
友情链接
搜索到
1
篇
标签
vue
下的文章
2022-07-20
[Vue3]Toast组件
组件代码 Toast.vue<!-- * @Description: 提示组件 * @Version: 1.0.0 * @Autor: susu<nongxuewang@qq.com> * @Date: 2022-07-07 23:17:35 * @LastEditTime: 2022-07-20 14:06:09 --> <template> <div class="toast" :style="{ background: background }">{{ message }}</div> </template> <script> import { reactive } from 'vue' export default { name: 'Toast', props: ['message', 'status'], metheds: { status2color: function (status){ let color = '#5FB878'; switch (status) { case 'error': color = '#FF5722'; break; case 'success': color = '#5FB878'; break; case 'warn': color = '#FFB800'; break; case 'info': color = '#1E9FFF'; break; case 'dark': color = '#393D49'; break; } return color; } }, computed: { background() { return this.status2color(this.status); } } } export const useToastEffect = () => { const toastData = reactive({ showToast: false, toastMessage: '', status: '', }) const showToast = (message, status, timeout) => { toastData.showToast = true toastData.toastMessage = message toastData.status = status; if (!timeout) { timeout = 2000; } setTimeout(() => { toastData.showToast = false toastData.toastMessage = '' }, timeout) } return { toastData, showToast } } </script> <style> .toast { position: fixed; z-index: 2000; right: 0; padding-right: 5%; top: 100px; transition: all .5s; -webkit-transform: translateX(-50%) translateY(-50%); -moz-transform: translateX(-50%) translateY(-50%); -ms-transform: translateX(-50%) translateY(-50%); -o-transform: translateX(-50%) translateY(-50%); transform: translateX(-50%) translateY(-50%); text-align: center; border-radius: 5px; color: #FFF; background: rgba(17, 17, 17, 0.7); height: 45px; line-height: 45px; padding: 0 15px; } </style>使用组件<template> <Toast v-if="toastData.showToast" :message="toastData.toastMessage" :status="toastData.status" /> </template> <script> import Toast, { useToastEffect } from '@/components/layui/Toast.vue'; export default { setup() { const { toastData, showToast } = useToastEffect(); return { toastData, showToast }; }, methods: { // 定义事件方法 test: function (type) { this.showToast("发生错误", 'warn'); that.showToast("保存成功"); } }, components: { Toast }, }; </script>
2022年07月20日
14 阅读
0 评论
0 点赞