首页 > 教程 >
分享一个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) { } } }}</ >
下载链接:网站源码/小程序源码/网站模板下载
下载排行
- 最新720全景云系统/可生成小程序+带PC端+安装教程/价值800元的720云全景系统源码
- 最新去水印小程序源码分享/无需后台/对接接口/支持全网去水印功能
- thinkphp资源源码付费下载站网站源码
- 大红喜庆版UI猜灯谜小程序源码/猜字谜微信小程序源码
- 最新JustMedia V2.7.3主题破解版去授权WordPress主题模板
- 爱看小说网源码全站带数据打包/ThinkPHP内核小说网站源码
- 小旋风万能蜘蛛池x9.02开心版/站长必备SEO/永久使用/带教程
- RiPro8.7免授权版+极致子主题破解版jizhi-chlid-v5.6-zhankr/WordPress主题模板
- 微信小程序秀才成语接龙趣味答题小游戏带流量主源码
- 智能AI客服系统源码/20国语言在线客服系统源码