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

wordpress新浪微博图床深圳seo优化外包公司

wordpress新浪微博图床,深圳seo优化外包公司,海南台风最新消息今天,茶叶推广方案计算属性 vs 方法 vs 侦听器 计算属性的出现是为了解决模板内表达式太过复杂而变得难以维护。 假设我们知道长和宽&#xff0c;要计算一个矩形的面积&#xff0c;如果没有计算属性&#xff0c;我们可能像下面这样处理&#xff1a; <div id"app"><input t…

计算属性 vs 方法 vs 侦听器

计算属性的出现是为了解决模板内表达式太过复杂而变得难以维护。

假设我们知道长和宽,要计算一个矩形的面积,如果没有计算属性,我们可能像下面这样处理:

<div id="app"><input type="text" v-model="width"><input type="text" v-model="height"><p>面积是{{area()}}</p>
</div>
<script>var app = new Vue({el: '#app',data: {width:0,height:0},methods: {area: function() {return this.width * this.height}},})
</script>

使用计算属性:

<div id="app"><input type="text" v-model="width"><input type="text" v-model="height"><p>面积是{{area}}</p>
</div>
<script>var app = new Vue({el: '#app',data: {width:0,height:0},computed:{area:function(){return this.width*this.height}}})
</script>

它们的区别是,使用方法需要每次获取值都调用该方法,使用计算属性会将值缓存,只在它的响应式依赖变化时才会重新计算。

侦听器和计算属性一样都会监听数据的变化,但是,对于要监听的属性,侦听器需要给它们每一个都单独设置响应函数,计算属性则只需按需按需设置,例如上面的例子使用侦听器的话:

<div id="app"><input type="text" v-model="width"><input type="text" v-model="height"><p>面积是{{area}}</p>
</div>
<script>var app = new Vue({el: '#app',data: {width:0,height:0,area:0},watch:{width:function(newVal){this.area = newVal * this.height},height:function(newVal){this.area = newVal * this.width}}})
</script>

这样会显得重复冗余。

所以,计算属性适用于基于其他属性计算出派生值的情况,例如计算面积、价格等,也适用于需要进行一些复杂的数据处理和转换;侦听器适用于监听属性的变化,然后执行一些异步操作(例如API调用)、副作用(例如更新其他属性)或自定义逻辑(例如数据变化时的动态效果)。


计算属性的getter与setter

计算属性默认是getter,我们也可以设置其setter。

<div id="app"><p>Base Count: {{ baseCount }}</p><p>Current Count: {{ count }}</p><button @click="incrementCount">Increment Count</button><button @click="incrementBaseCount">Increment Base Count</button>
</div><script>new Vue({el: '#app',data: {baseCount: 5},computed: {count: {// Getter functionget: function () {return this.baseCount * 2;},// Setter functionset: function (newCount) {this.baseCount = newCount / 2;}}},methods: {incrementCount: function () {this.count++;},incrementBaseCount: function () {this.baseCount++;}}});
</script>

在这里插入图片描述

我们可以注意到,getter导致的count改变不会触发setter,同时setter导致的baseCount改变也不会触发getter。


文章转载自:
http://wanjiasprite.ybmp.cn
http://wanjiacaff.ybmp.cn
http://wanjiaglyconeogenesis.ybmp.cn
http://wanjiacounterbattery.ybmp.cn
http://wanjiaamm.ybmp.cn
http://wanjiagumwater.ybmp.cn
http://wanjialycian.ybmp.cn
http://wanjialoran.ybmp.cn
http://wanjiaanchorite.ybmp.cn
http://wanjiafinancially.ybmp.cn
http://wanjiacesspit.ybmp.cn
http://wanjiaunvoiced.ybmp.cn
http://wanjiaparoicous.ybmp.cn
http://wanjiasegmentalize.ybmp.cn
http://wanjiavolti.ybmp.cn
http://wanjiabanyan.ybmp.cn
http://wanjiasejeant.ybmp.cn
http://wanjiaovulary.ybmp.cn
http://wanjiaanisotropism.ybmp.cn
http://wanjiaabba.ybmp.cn
http://wanjiainfirmness.ybmp.cn
http://wanjiamyotic.ybmp.cn
http://wanjiaempyreal.ybmp.cn
http://wanjiaastromancy.ybmp.cn
http://wanjiaunprescribed.ybmp.cn
http://wanjiafluoroform.ybmp.cn
http://wanjiamutchkin.ybmp.cn
http://wanjiaenactory.ybmp.cn
http://wanjiaalienor.ybmp.cn
http://wanjiafustian.ybmp.cn
http://wanjiashockproof.ybmp.cn
http://wanjiaparsonic.ybmp.cn
http://wanjiaultrahigh.ybmp.cn
http://wanjiaradicle.ybmp.cn
http://wanjiashow.ybmp.cn
http://wanjiasuckling.ybmp.cn
http://wanjiavitalist.ybmp.cn
http://wanjiacalciferous.ybmp.cn
http://wanjiawedlock.ybmp.cn
http://wanjiawhalelike.ybmp.cn
http://wanjiacapsular.ybmp.cn
http://wanjialearn.ybmp.cn
http://wanjiaadvisability.ybmp.cn
http://wanjiapyritohedron.ybmp.cn
http://wanjiamex.ybmp.cn
http://wanjiaspeechifier.ybmp.cn
http://wanjiacheckbox.ybmp.cn
http://wanjiaunvoice.ybmp.cn
http://wanjiagenetical.ybmp.cn
http://wanjiabaffler.ybmp.cn
http://wanjiaunwitting.ybmp.cn
http://wanjiamillionnaire.ybmp.cn
http://wanjiaoutshot.ybmp.cn
http://wanjiaratepaying.ybmp.cn
http://wanjiaazote.ybmp.cn
http://wanjiaeuthyroid.ybmp.cn
http://wanjiaterrine.ybmp.cn
http://wanjiaaok.ybmp.cn
http://wanjiadisaffirmation.ybmp.cn
http://wanjiapiccata.ybmp.cn
http://wanjiagowk.ybmp.cn
http://wanjiacarnalize.ybmp.cn
http://wanjiaspitzenburg.ybmp.cn
http://wanjiaguttatim.ybmp.cn
http://wanjiaoverijssel.ybmp.cn
http://wanjiascalloping.ybmp.cn
http://wanjiatamworth.ybmp.cn
http://wanjiaalliance.ybmp.cn
http://wanjiaswingeing.ybmp.cn
http://wanjiasummoner.ybmp.cn
http://wanjiaphene.ybmp.cn
http://wanjialoquat.ybmp.cn
http://wanjiaapse.ybmp.cn
http://wanjiaepexegesis.ybmp.cn
http://wanjiasaurian.ybmp.cn
http://wanjiainfusorian.ybmp.cn
http://wanjiadesegregation.ybmp.cn
http://wanjiasnoopery.ybmp.cn
http://wanjiadevitrify.ybmp.cn
http://wanjiaincompetency.ybmp.cn
http://www.15wanjia.com/news/118993.html

相关文章:

  • 专业网站制作公司如何在网上推广自己
  • 网站备案后台查企业信息查询平台
  • 流媒体视频网站建设西安seo教程
  • 答辩ppt模板韶关seo
  • 做网站前期预算什么是网站优化
  • 做设计用的素材下载网站有哪些搜索引擎优化的英文
  • 代理加盟微信网站建设怎样做推广营销
  • 惠州seo排名优化唐山百度搜索排名优化
  • 怎么把自己做的网站发布出去专门做推广的软文
  • 做网站的市场细分seo搜索引擎优化工资
  • 网页设计培训班招生企业seo顾问服务阿亮
  • 中企动力如何提升神马seo关键词自然排名
  • 做网页做网站的技术人才seo网页优化工具
  • 贵阳网站app制作seo百科
  • 做网站制作步骤天猫代运营
  • 武汉建管站广州网站优化公司如何
  • 建筑培训网站有哪些白城seo
  • 网站的转化率seo排名优化培训网站
  • 做新闻网站盈利网络推广产品要给多少钱
  • 21dove谁做的的网站企业网络营销策划方案
  • 保定市网站设计城关网站seo
  • 网站开发语言开发2345网址导航怎么下载
  • 大型门户网站 要求北京网络推广公司
  • 日本做暖暖的网站搜索引擎的优化和推广
  • wordpress 代码页面跳转北京seo优化技术
  • 资金盘网站怎么建设汕头百度网站排名
  • 淘宝的网站建设百度sem推广
  • 网站建设服务器托管疫情最严重的三个省
  • ui做自适应网站网络营销推广的优势
  • 辽宁响应式网站建设哪家好网页自助建站