首页 > 教程 >
分享一个VUE页面声音+标题闪烁通知的组件(附使用方法)
2023-02-23教程围观次
简介本篇文章给大家分享一个VUE页面声音+标题闪烁通知的组件,聊聊具体怎么使用这个组件,希望对大家有所帮助。1.使用方法1.1组件模板引用1.2支持的参数sound:通知时播放的声音1.3动态调用方法$refs.pageNotice.tip('你好','新消息')$refs.pageNotice.tip('有新客户访问')2.组件源码PageNotice组件源代码如下exportdefault{nam
本篇文章给大家分享一个VUE页面声音+ 标题闪烁通知的组件,聊聊具体怎么使用这个组件 ,希望对大家有所帮助。
1.使用方法
1.1 组件模板引用
<PageNotice ref="pageNotice" sound="/xxx/new_message.mp3" />
1.2 支持的参数
sound: 通知时播放的声音
1.3 动态调用方法
$refs.pageNotice.tip('你好','新消息') $refs.pageNotice.tip('有新客户访问')
2.组件源码
PageNotice 组件源代码如下
<template> <div> <audio ref="audio" :src="sound"></audio> </div></template>< >export default { name: "PageNotice", props: { sound: { type: String, default: '' }, }, data() { return { tipTimer: null, tipTimerCount: 0, Old: null, } }, methods: { tip(msg, type) { this.doPage (msg, type) if (this.sound) { this.doPlaySound() } }, doClearTimer() { clearInterval(this.tipTimer) this.tipTimer = null if (this. Old) { window.document. = this. Old } this.tipTimerCount = 0 }, doPage (msg, type) { type = type || '提醒' if (this.tipTimer) { this.doClearTimer() } this. Old = document. this.tipTimerCount = 0 this.tipTimer = setInterval(() => { this.tipTimerCount++ if (this.tipTimerCount % 2 === 0) { window.document. = '【' + type + '】' + msg } else { window.document. = '' + msg } if (this.tipTimerCount > 6) { this.doClearTimer() } }, 500) }, doPlaySound() { let audio = this.$refs.audio if (!audio) { return } try { audio.pause() audio.play() } catch (e) { } } }}</ >
下载链接:网站源码/小程序源码/网站模板下载
下载排行
- 多套头像/壁纸/背景图资源微信小程序源码 粉色UI 带流量主
- 全新UI简洁H5商城网站源码/带易支付接口
- PHP在线考试系统4.0版本源码电脑+手机端
- 某鱼最近卖的很火蓝色版微信去水印小程序源码+接口
- 简约自适应wordpress博客二次元主题qzdy4.3
- 壁纸头像/动态壁纸小程序源码-支持用户投稿-带部分采集功能+视频搭建教程
- EyouCMS响应式苗木园林绿化公司模板/易优CMS农业林业类企业网站模板
- 全套打包微社区/西瓜同城分类信息系列打包整套插件(30个插件+小程序)
- 爱看小说网源码全站带数据打包/ThinkPHP内核小说网站源码
- 最新PHP短网址生成系统/短链接生成系统/URL缩短器系统源码