当前位置: 首页 > news >正文

wordpress站点字体修改品牌推广活动策划案例

wordpress站点字体修改,品牌推广活动策划案例,上海高端网站建设服务公,西部数码网站管理助手使用教程vue2中使用web worker启动定时器,避免浏览器最小化或切换标签页时定时器不能按设定周期执行【一般是周期小于60s时,大于60s一般可正常执行】 1、添加worker-loader2、修改vue.config.js3、创建timer.worker.js4、创建TimerWorker.js5、使用TimerWorker启…

vue2中使用web worker启动定时器,避免浏览器最小化或切换标签页时定时器不能按设定周期执行【一般是周期小于60s时,大于60s一般可正常执行】

  • 1、添加worker-loader
  • 2、修改vue.config.js
  • 3、创建timer.worker.js
  • 4、创建TimerWorker.js
  • 5、使用TimerWorker启动定时任务

1、添加worker-loader

npm install worker-loader --save

2、修改vue.config.js

新增以下配置

 config.module.rule('workers').test(/\.worker\.js$/).use('worker-loader').loader('worker-loader').options({inline: 'fallback'  // 尝试内联,失败则回退到默认行为})

3、创建timer.worker.js

self.timers = {}self.onmessage = function(event) {const { action, id, interval } = event.dataswitch (action) {case 'startTimer':startTimer(id, interval)breakcase 'stopTimer':stopTimer(id)breakcase 'stopAllTimers':stopAllTimers()break}
}function startTimer(id, interval) {if (!self.timers[id]) {self.timers[id] = setInterval(() => {self.postMessage({ id })}, interval)}
}function stopTimer(id) {if (self.timers[id]) {clearInterval(self.timers[id])delete self.timers[id]}
}function stopAllTimers() {Object.keys(self.timers).forEach(id => {clearInterval(self.timers[id])})self.timers = {}
}

4、创建TimerWorker.js

import Worker from './timer.worker.js'export default class TimerWorker {worker;timers;constructor() {this.start()}startTimer(id, interval, fun) {if (this.worker && !this.timers[id]) {this.timers[id] = funthis.worker.postMessage({ action: 'startTimer', id, interval })}return this}stopTimer(id) {if (this.worker && this.timers[id]) {this.worker.postMessage({ action: 'stopTimer', id })delete this.timers[id]}return this}stopAllTimers() {if (this.worker) {this.worker.postMessage({ action: 'stopAllTimers' })this.timers = {}}return this}start() {if (!this.worker) {const worker = new Worker()worker.onmessage = (event) => {this.timers[event.data.id]()}this.worker = workerthis.timers = {}}return this}terminate() {if (this.worker) {this.stopAllTimers()this.worker.terminate()this.worker = undefinedthis.timers = undefined}return this}
}

5、使用TimerWorker启动定时任务

import TimerWorker from './TimerWorker'export default {...created() {this._timerWorker = new TimeWorker()this.startTimer()},beforeDestroy() {this._timerWorker.terminate()},methods: {startTimer() {this._timeWorker.startTimer('test', 100, () => {console.log(new Date().getTime())})}}...
}
http://www.ds6.com.cn/news/67305.html

相关文章:

  • 南隼深圳网站建设app如何推广以及推广渠道
  • js特效网站展示百度竞价一个月5000够吗
  • 重庆网站自己推广百度竞价seo排名
  • 网站开发工具js新网站快速排名软件
  • c2c网站建设价格游戏加盟
  • 教做饮品的网站谷歌ads
  • 建设银行网站用户名是什么意思网站备案查询
  • 担路网做网站多少钱去哪里推广软件效果好
  • 建设有限公司首页郑州网站优化平台
  • 网站如何做的有特色免费网络空间搜索引擎
  • 网站申请备案成功后怎么建设seo优化主要做什么
  • 重庆公司做网站海南seo
  • 做系统用什么网站怎样在百度上建立网站
  • 网页设计公司取名温州seo推广外包
  • 水泥网站营销方案怎么做网店推广的方式
  • 类似千图网的素材网站电商产品推广方案
  • 望京网站建设公司网络营销怎么做?
  • 邯郸网站建设公司大连seo网站推广
  • 张家口做网站多少钱泰州网站优化公司
  • 龙岩网站制作公司网站关键词优化费用
  • 烟台网站开发制作百度首页 百度
  • 建行手机app下载开源seo软件
  • 做的比较好旅游网站推广平台的方式有哪些
  • 保定网站建设技术支持网络广告的发布方式包括
  • 上海seo优化外包公司无锡seo排名收费
  • 网站建设合同的性质济南市新闻最新消息
  • 2003访问网站提示输入用户名密码百度网页入口
  • wordpress小说网站模板下载地址网页设计模板网站免费
  • 北京做网站海宇勇创如何宣传推广自己的店铺
  • 公司企业网站怎么建设seo软件开发