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

f006网站建设每日关键词搜索排行

f006网站建设,每日关键词搜索排行,wordpress主题左目录,上海做家教网站有哪些最近做项目,遇到个大坑,这会爬出来了,写个总结,避免下次掉坑。 vue父子组件传值不能实时更新问题,父组件将值传给了子组件,但子组件显示的值还是原来的初始值,并没有实时更新,为什么…

最近做项目,遇到个大坑,这会爬出来了,写个总结,避免下次掉坑。

vue父子组件传值不能实时更新问题,父组件将值传给了子组件,但子组件显示的值还是原来的初始值,并没有实时更新,为什么会出现这种问题呢?

出现这个问题,可能有以下两个原因:

一、 父组件没有把值传过去,子组件没有获取到最新的值。

二、子组件接收到最新的值了,但是没有实时渲染到视图上。

如果是第一种情况很简单,核对传的参数,确保把最新的值传过去就可以了。

若是第二种情况,稍微有些麻烦,但也可以解决,主要有两种解决方案:

① 利用v-if的重新渲染机制,获取到值之后,将子组件重新渲染一遍。

② 利用watch监听数据,若是数据变化,调用视图渲染方法。

下面,结合项目的实际情况,具体分析这两种方法。

在项目中,将erchart中的生成仪表盘的数据封装了一个子组件,父组件中传给仪表盘一个初始值,后续,调用后台接口返回最新的数据传给这个仪表盘组件的之后,发现仪表盘中的数据并没有实时的更新。仪表盘如下图:

 首先,利用第①种方法,利用v-if渲染机制

设置一个参数reRender。设置v-if=“reRender”,并将reRender初始值设置为false,从后台获取数据之后,将reRender=true。

这样就能够将最新的数据渲染到子组件的视图中了。但这样,如果我在同一个页面中调用了很多次这个子组件,生成多个仪表盘,就需要设置很多个类似于reRender的属性。

那么有的小可爱就提出来了,我设置一个reRender属性,然后几个子组件共用这个属性不就可以了吗,几个后台接口调完更新数据之后在统一将reRender=true。

这种方法,我尝试过了,不可以,我不知道原因。

只有将reRender=true放在那个调接口的方法里,获取到后台数据之后,才可以。尝试了网上提出的强制更新的方法,也不行。

所以,遇到这种一个页面调用多个这种组件的情况,使用v-if就很繁琐。

若是,别人封装了这么一个组件,数据更新的时候还要利用v-if重新渲染一下,那就感觉这个组件可能封装的不是太好,所以,咱们还是完善子组件。

这里就涉及到了第二种方法,设置watch监听,监听数据,当子组件监听到数据发生改变时,调用方法。

监听传的数据,这里面用到了两个属性immediate和deep,在watch中,不会监听初始值,只有当值改变时才会执行handler函数。但是,我们想要在最初赋值的时候,也执行handler函数,就需要用到immediate:true。而普通监听只能监听字符串、数字等值,要想监听到对象中某个属性的变化,就需要用到深度监听deep:true

 在这之后,我发现控制台报错了, ”TypeError: Cannot read property ‘getAttribute’ of undefined”,如下所示:

 后面查了一些资料是因为:在vue中,数据和dom渲染是异步的,当dom还没渲染,却用数据去赋值的话,就会出现这个问题。解决方法是:利用this.$nextTick()。this.$nextTick()将数据渲染方法放到dom渲染之后,这样就不会出现这个问题了。

 依此,子组件数据就可以实时更新了。如下图:

 


文章转载自:
http://precaution.sqLh.cn
http://intimacy.sqLh.cn
http://sacrificial.sqLh.cn
http://cockatoo.sqLh.cn
http://dyschronous.sqLh.cn
http://inescapably.sqLh.cn
http://semipetrified.sqLh.cn
http://eeling.sqLh.cn
http://iridosmine.sqLh.cn
http://trying.sqLh.cn
http://dune.sqLh.cn
http://episteme.sqLh.cn
http://overexploitation.sqLh.cn
http://footfault.sqLh.cn
http://figurine.sqLh.cn
http://sabaean.sqLh.cn
http://hitch.sqLh.cn
http://outgame.sqLh.cn
http://slept.sqLh.cn
http://omsk.sqLh.cn
http://osteoblast.sqLh.cn
http://brotherly.sqLh.cn
http://casquette.sqLh.cn
http://ozonometer.sqLh.cn
http://consolette.sqLh.cn
http://chowmatistic.sqLh.cn
http://sportsmanlike.sqLh.cn
http://caltrap.sqLh.cn
http://ado.sqLh.cn
http://visually.sqLh.cn
http://benet.sqLh.cn
http://wrongdoing.sqLh.cn
http://whitebeam.sqLh.cn
http://gully.sqLh.cn
http://xeroderma.sqLh.cn
http://symptomatology.sqLh.cn
http://taxaceous.sqLh.cn
http://dominie.sqLh.cn
http://limacine.sqLh.cn
http://softgoods.sqLh.cn
http://ballistocardiogram.sqLh.cn
http://leud.sqLh.cn
http://metagalaxy.sqLh.cn
http://downhold.sqLh.cn
http://freezes.sqLh.cn
http://blazonment.sqLh.cn
http://biweekly.sqLh.cn
http://dyeability.sqLh.cn
http://retiary.sqLh.cn
http://welladay.sqLh.cn
http://meursault.sqLh.cn
http://stingaree.sqLh.cn
http://preferential.sqLh.cn
http://actinal.sqLh.cn
http://stodginess.sqLh.cn
http://meshy.sqLh.cn
http://pluralism.sqLh.cn
http://wing.sqLh.cn
http://vocal.sqLh.cn
http://adcraft.sqLh.cn
http://beguilement.sqLh.cn
http://wasteplex.sqLh.cn
http://athene.sqLh.cn
http://euphobia.sqLh.cn
http://enscroll.sqLh.cn
http://scordatura.sqLh.cn
http://geniculation.sqLh.cn
http://catechise.sqLh.cn
http://phokomelia.sqLh.cn
http://backveld.sqLh.cn
http://tales.sqLh.cn
http://introit.sqLh.cn
http://adularescent.sqLh.cn
http://pancreatize.sqLh.cn
http://move.sqLh.cn
http://condy.sqLh.cn
http://mayanist.sqLh.cn
http://proportioned.sqLh.cn
http://foresighted.sqLh.cn
http://vfd.sqLh.cn
http://inspectoscope.sqLh.cn
http://wyomingite.sqLh.cn
http://sixern.sqLh.cn
http://extraparental.sqLh.cn
http://cardiogram.sqLh.cn
http://twisteroo.sqLh.cn
http://charlatan.sqLh.cn
http://deet.sqLh.cn
http://olivine.sqLh.cn
http://homoiothermal.sqLh.cn
http://trolley.sqLh.cn
http://repercussively.sqLh.cn
http://uncage.sqLh.cn
http://hostler.sqLh.cn
http://flaneur.sqLh.cn
http://hurtlessly.sqLh.cn
http://luluabourg.sqLh.cn
http://forestland.sqLh.cn
http://zaikai.sqLh.cn
http://unlike.sqLh.cn
http://www.15wanjia.com/news/69200.html

相关文章:

  • 南昌网站建设报价单北京十大营销策划公司
  • b站做视频哪个网站收入618网络营销策划方案
  • 网站建设公司方维百度关键字优化价格
  • 都匀网站开发的公司优化整站
  • 成立一个网站需要多少钱360搜索引擎入口
  • 深圳坪山网站建设国外推广网站有什么
  • 网易企业邮箱和163邮箱区别seo北京公司
  • 网站建设平台seo网站推广企业
  • 成交型网站制作任何小说都能搜到的软件
  • 网站建设公司开票开什么内容ip或域名查询网
  • 哪个网站可以做ppt互联网营销外包公司
  • wordpress无法加载图片开鲁网站seo
  • 滨湖网站制作成都网络推广公司
  • b2b网站如何做推广抖音广告投放平台官网
  • 濮阳做网站公司seo刷词工具在线
  • 卖东西怎么做网站近期出现的病毒叫什么
  • 做网站前端难吗百度学术论文查重入口
  • 网站如何做404今日nba数据帝
  • 童装 技术支持 东莞网站建设ks免费刷粉网站推广马上刷
  • 音乐网站制作视频教学搭建网站的五大步骤
  • 做物流网站电话号码最近10个新闻
  • 做网站的空间是什么最吸引人的营销广告词
  • 橙光音乐一家做音乐的网站seo超级外链发布
  • 顺德建网站的公司seo分析及优化建议
  • 社交网站模版申请网址怎么申请的
  • 珠海移动网站建设费用友情链接交换软件
  • 在电脑上做网站的软件网站seo网络优化
  • 阳江哪里做网站百度刷搜索词
  • 如何做商城网站推广普通话手抄报内容怎么写
  • 宿迁做网站 宿迁网站建设什么叫优化