vue项目如何实现标题闪烁通知,并且附带声音提示效果!下面编程教程网小编带大家了解一下!
新建一个Notice组件
<template>
<div>
<audio ref="audio" :src="sound"></audio>
</div>
</template>
<script>
export default {
name: "Notice",
props: {
sound: {
type: String,
default: ''
},
},
data() {
return {
tipTimer: null,
tipTimerCount: 0,
titleOld: null,
}
},
methods: {
tip(msg, type) {
this.doPageTitle(msg, type)
if (this.sound) {
this.doPlaySound()
}
},
doClearTimer() {
clearInterval(this.tipTimer)
this.tipTimer = null
if (this.titleOld) {
window.document.title = this.titleOld
}
this.tipTimerCount = 0
},
doPageTitle(msg, type) {
type = type || '提醒'
if (this.tipTimer) {
this.doClearTimer()
}
this.titleOld = document.title
this.tipTimerCount = 0
this.tipTimer = setInterval(() => {
this.tipTimerCount++
if (this.tipTimerCount % 2 === 0) {
window.document.title = '【' + type + '】' + msg
} else {
window.document.title = '' + msg
}
if (this.tipTimerCount > 6) {
this.doClearTimer()
}
}, 500)
},
doPlaySound() {
let audio = this.$refs.audio
if (!audio) {
return
}
try {
audio.pause()
audio.play()
} catch (e) {}
}
}
}
</script>
Notice组件引用
<noticeCon ref="noticeConRefs" sound="message.mp3"></noticeCon>
调用方法
this.$refs.noticeConRefs.tip('hello','新消息')
以上是编程学习网小编为您介绍的“vue项目如何实现标题闪烁通知效果(附带声音提示)”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。
编程基础网
本文标题为:vue项目如何实现标题闪烁通知效果(附带声音提示)
基础教程推荐
猜你喜欢
- pdfjs预览 vue中常见的坑及修改预览的标题名 2023-10-08
- 清除css浮动的三种方法小结 2023-12-19
- vue-router两种模式区别及使用注意事项详解 2024-02-10
- clear 万能清除浮动(clearfix:after) 2024-01-09
- Vue项目中如何处理组件之间的各种通信? 2025-01-12
- 客户端js判断文件类型和文件大小即限制上传大小 2024-03-09
- selenium+python自动化测试之页面元素定位 2023-12-08
- 页面只能打开一次Cooike如何实现 2024-01-12
- Vue:三种情况下的生命周期执行顺序 2023-10-08
- jquery实现滑动特效代码 2024-02-07
