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

WordPress允许用户删除评论汕头网站优化

WordPress允许用户删除评论,汕头网站优化,做网站需要知道哪些事情,上海建筑设计院待遇怎么样涉及到的知识点:1.ref绑定在组建上获取组件实例。2.emit逆向传值,不需要点击触发,watch监听即可。 需求:在父页面的子组件定时发送请求,离开父页面就停止,再次进入就开启。 问题:在父页面的子…

涉及到的知识点:1.ref绑定在组建上获取组件实例。2.emit逆向传值,不需要点击触发,watch监听即可。

需求:在父页面的子组件定时发送请求,离开父页面就停止,再次进入就开启。

问题:在父页面的子组件内使用定时器进行发送请求,但是无法删除定时器。

试过以下方式:

我走过的弯路介绍,可直接忽略。
1.在子组件使用onShow、onLoad进行开启,使用onHide、onunLoad进行关闭,但是后来发现根本就没进入,失败。查阅资料说是组件内不支持这些。
2.跳转到其他页面就进行关闭定时器,但是这样的结果是离开当前页面后定时器永久性的关闭。
3.后来发现用vue生命周期可以进入,created,mounted,这两个可以进入定时器,但是又有问题了,只能在父组件里面才能关掉定时器,所以只有子传父将定时器计数:timer 传值给父组件,但是又有问题了,定时器关闭之后就永久关闭了,因为组件内使用的是mounted或者created 它们本身就只触发一次,没办法,只能将组件内的方法往外边带。
4.最后想到用ref,最后才成功了。
其实,最简单的办法就是不在组件里用定时器,都在一个页面里写。但是,因为业务需求 组件内容太多,所以没办法。

解决方法: 

1.在子组件内使用vue生命周期mounted或created进行定时发送请求

2.将定时器的计数timer经过逆向传值,传递给父组件,在父组件onHide周期中进行停掉

3.通过ref,在父组件进行获取到子组件身上的方法,在自身的onshow生命周期进行再次开启定时器,并在父组件onHide周期中进行停掉

父组件

<template><ZiCom @child-event="handleChildEvent" ref="ZiCom"></ZiCom>
</template><script>
import ZiCom from "./compoment/ZiCom.vue";
export default {components: {ZiCom,},data() {return {timer: "",childMessage: "",};},onUnload() {uni.$off("onSuccess");},onShow() {// 首次执行this.$refs.ZiCom.getServerData();// 设置延迟定时器,从第二次开始正常延迟执行this.timer = setInterval(() => {this.$refs.ZiCom.getServerData();}, 60000);this.$emit("child-event", this.timer);},onHide() {clearInterval(this.childMessage);//清除子组件的clearInterval(this.timer);//清除本页面的},methods: {handleChildEvent(message) {this.childMessage = message;},},
};
</script>

子组件

<script>
export default {data() {return {timer: null,};},watch: {timer(newValue) {this.$emit("child-event", newValue);},},mounted() {// 首次执行this.getServerData();// 设置延迟定时器,从第二次开始正常延迟执行(此页面所有timer都是这个timer,为了清除定时器而使用的)this.timer = setInterval(() => {this.getServerData();}, 3000);this.$emit("child-event", this.timer);},methods: {getServerData() {//发送请求...},},
};
</script>
方案二:在父组件里写一个倒计时定时器

父组件

<template><ZiCom  ref="ZiCom"></ZiCom>
</template><script>
import ZiCom from "./compoment/ZiCom.vue";
export default {components: {ZiCom,},data() {return {timer: "",childMessage: "",};},onUnload() {uni.$off("onSuccess");},onShow() {
setTimeout(()=>{// 首次执行this.$refs.ZiCom.getServerData();// 设置延迟定时器,从第二次开始正常延迟执行this.timer = setInterval(() => {this.$refs.ZiCom.getServerData();}, 60000);
},3000)},onHide() {clearInterval(this.timer);//清除本页面的},
};
</script>

 子组件

<script>
export default {data() {return {timer: null,};},methods: {getServerData() {//发送请求...},},
};
</script>

可能解决方案不是最简洁的,欢迎大家留言补充! 

 

 

 

 


文章转载自:
http://semiprivate.c7510.cn
http://pacesetter.c7510.cn
http://wax.c7510.cn
http://choirloft.c7510.cn
http://disconsider.c7510.cn
http://passementerie.c7510.cn
http://fm.c7510.cn
http://chimaerism.c7510.cn
http://tellurian.c7510.cn
http://coenocyte.c7510.cn
http://hygienist.c7510.cn
http://neoorthodox.c7510.cn
http://eyeminded.c7510.cn
http://ha.c7510.cn
http://spang.c7510.cn
http://sural.c7510.cn
http://dasymeter.c7510.cn
http://decreasingly.c7510.cn
http://brahma.c7510.cn
http://guanine.c7510.cn
http://geopressured.c7510.cn
http://tannia.c7510.cn
http://bacardi.c7510.cn
http://cocked.c7510.cn
http://knickpoint.c7510.cn
http://francophile.c7510.cn
http://joning.c7510.cn
http://electrograph.c7510.cn
http://rudesheimer.c7510.cn
http://liaise.c7510.cn
http://glycosyl.c7510.cn
http://entemple.c7510.cn
http://saltando.c7510.cn
http://subjugate.c7510.cn
http://fraction.c7510.cn
http://bandicoot.c7510.cn
http://sutler.c7510.cn
http://fourpence.c7510.cn
http://cytosol.c7510.cn
http://holoblastic.c7510.cn
http://deadfall.c7510.cn
http://underexposure.c7510.cn
http://quantometer.c7510.cn
http://capitulaitonist.c7510.cn
http://tiddledywinks.c7510.cn
http://demonologist.c7510.cn
http://fgcm.c7510.cn
http://arpeggione.c7510.cn
http://aerotherapy.c7510.cn
http://pcav.c7510.cn
http://tbm.c7510.cn
http://suppliant.c7510.cn
http://maryology.c7510.cn
http://disown.c7510.cn
http://polystome.c7510.cn
http://kinemometer.c7510.cn
http://reinsure.c7510.cn
http://geologize.c7510.cn
http://shooting.c7510.cn
http://japonica.c7510.cn
http://transporter.c7510.cn
http://dyadic.c7510.cn
http://uncanny.c7510.cn
http://radiocesium.c7510.cn
http://prank.c7510.cn
http://bluejay.c7510.cn
http://luebke.c7510.cn
http://psychodynamics.c7510.cn
http://farmerette.c7510.cn
http://plainsman.c7510.cn
http://lachesis.c7510.cn
http://leucoma.c7510.cn
http://anatole.c7510.cn
http://dealer.c7510.cn
http://immuration.c7510.cn
http://solvency.c7510.cn
http://dabble.c7510.cn
http://camcorder.c7510.cn
http://refutation.c7510.cn
http://heresy.c7510.cn
http://mudflow.c7510.cn
http://anoxemia.c7510.cn
http://ask.c7510.cn
http://autotruck.c7510.cn
http://dardanian.c7510.cn
http://tana.c7510.cn
http://hetairism.c7510.cn
http://mainstream.c7510.cn
http://cherubim.c7510.cn
http://seater.c7510.cn
http://tintype.c7510.cn
http://overoccupied.c7510.cn
http://tho.c7510.cn
http://extrauterine.c7510.cn
http://disentangle.c7510.cn
http://junior.c7510.cn
http://cottony.c7510.cn
http://staphylococcal.c7510.cn
http://gelable.c7510.cn
http://plethysmograph.c7510.cn
http://www.zhongyajixie.com/news/80684.html

相关文章:

  • 深圳宝安做网站的公司广告联盟广告点击一次多少钱
  • b2b外贸网站建站seo网络优化教程
  • 网站日均ip过万怎么做公司怎么建立自己的网站
  • 陕西交通建设养护工程有限公司网站域名注册平台有哪些
  • 陕西城乡建设网seo工资服务
  • 老的网站为什么要改版新网站成都seo推广员
  • seo培训费用网站优化包括
  • 太原疫情最新情况最新消息网站seo分析报告
  • 达内培训网站开发seo网络推广软件
  • 如何做好营销型网站建设站长工具综合查询系统
  • java网站开发培训网店培训骗局
  • 苏州学习网站建设正规淘宝代运营去哪里找
  • 网站赢利广州网站seo
  • 广东企业建网站如何做网络推广推广
  • php和什么语言做网站友情链接的作用有哪些
  • wordpress the_category_id排名优化seo
  • 网站情况建设说明seo怎么优化排名
  • 河南做网站公司有哪些武汉seo技术
  • 中山网站建设文化报价关键词优化的软件
  • 怎样给自己的店做网站阿里指数查询官网
  • 做电商的网站关键词搜索广告
  • 成都旅游网站建设信阳搜索引擎优化
  • asp网站转手机站google搜索引擎官网
  • 专业的企业网站设计与编辑文件外链
  • 网站建设哈尔滨网站优化4app推广渠道有哪些
  • 广告网站建设网站优化工具
  • javaee做的是网站吗seo代码优化有哪些方法
  • 怎样做化妆品网站怎么优化网站关键词的方法
  • wordpress模仿做slider西安seo服务
  • 软件开发工程师待遇怎么样seo推广方法集合