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

v9做的网站被攻击链接吧跳转今天最新军事新闻视频

v9做的网站被攻击链接吧跳转,今天最新军事新闻视频,深圳便宜网站建设,装修公司网站模板vue3 学习笔记08 – computed 和 watch computed computed 是 Vue 3 中用于创建计算属性的重要 API,它能够根据其它响应式数据动态计算出一个新的值,并确保在依赖数据变化时自动更新。 基本用法 squaredCount 是一个计算属性,它依赖于 count…

vue3 学习笔记08 – computed 和 watch

computed

computed 是 Vue 3 中用于创建计算属性的重要 API,它能够根据其它响应式数据动态计算出一个新的值,并确保在依赖数据变化时自动更新。

  1. 基本用法

    squaredCount 是一个计算属性,它依赖于 count 的值,并且会在 count 变化时自动更新

    import { ref, computed } from 'vue';// 定义一个响应式数据const count = ref(1);// 定义一个计算属性const squaredCount = computed(() => count.value * count.value);console.log(squaredCount.value); // 输出:1// 修改 count,触发计算属性更新count.value = 2;console.log(squaredCount.value); // 输出:4
  2. 缓存和计算属性的惰性求值

    computed 默认会缓存计算结果,只有在它的依赖项变化时才会重新计算。这样可以确保在性能上的优化,避免不必要的计算

         import { ref, computed } from 'vue';const count = ref(1);// 定义一个计算属性,使用 getter 函数const squaredCount = computed(() => {console.log('computed squaredCount'); // 仅在首次获取或依赖变化时输出return count.value * count.value;});console.log(squaredCount.value); // 输出:1count.value = 2;console.log(squaredCount.value); // 输出:4
  3. 计算属性的 setter

    在某些情况下,可能需要通过计算属性设置值。Vue 3 允许定义计算属性的 get 和 set 方法,使其可以作为双向绑定的源。

     import { ref, computed } from 'vue';const firstName = ref('John');const lastName = ref('Doe');const fullName = computed({get: () => `${firstName.value} ${lastName.value}`,set: (value: string) => {const names = value.split(' ');firstName.value = names[0];lastName.value = names[names.length - 1];}});console.log(fullName.value); // 输出:John DoefullName.value = 'Jane Smith';console.log(firstName.value); // 输出:Janeconsole.log(lastName.value); // 输出:Smith
  4. 在 Vue 组件中使用

    在 Vue 组件中,可以将计算属性直接用于模板中,而不需要额外的 .value 访问方式。

    <template><div><p>Count: {{ count }}</p><p>Squared Count: {{ squaredCount }}</p></div></template><script setup>import { ref, computed } from 'vue';const count = ref(1);const squaredCount = computed(() => count.value * count.value);</script>
watch

watch 函数用于监听一个响应式数据的变化,它可以用来执行一些副作用操作,比如异步请求、处理复杂逻辑或者更新状态

  1. 监听响应式数据的变化
  import { ref, watch } from 'vue';const count = ref(0);// 通过 watch 函数监听 count 的变化。每当 count 发生变化时,回调函数会被调用,同时传入新值 newValue 和旧值 oldValue。watch(count, (newValue, oldValue) => {console.log(`count changed from ${oldValue} to ${newValue}`);});
  1. 监听多个数据的变化
      import { ref, watch } from 'vue';const firstName = ref('John');const lastName = ref('Doe');watch([firstName, lastName], ([newFirst, newLast], [oldFirst, oldLast]) => {console.log(`Name changed from ${oldFirst} ${oldLast} to ${newFirst} ${newLast}`);});
  2. 异步处理和立即执行
  import { ref, watch } from 'vue';const count = ref(0);watch(count, async (newValue, oldValue) => {console.log(`count changed from ${oldValue} to ${newValue}`);// 异步操作示例try {await someAsyncOperation(newValue);} catch (error) {console.error('Async operation failed:', error);}}, { immediate: true }); // 立即执行回调函数
  1. 停止监听

    watch终止监听,只需要将watch赋值给一个变量,当达到条件调用watch赋值的那个变量就可以终止监听了

      import { ref, watch } from 'vue';const count = ref(0);const stopWatching = watch(count, (newValue, oldValue) => {console.log(`count changed from ${oldValue} to ${newValue}`);});// 停止监听stopWatching();

文章转载自:
http://approving.xxhc.cn
http://castnet.xxhc.cn
http://volumetric.xxhc.cn
http://zoogony.xxhc.cn
http://antisocial.xxhc.cn
http://appealing.xxhc.cn
http://araeostyle.xxhc.cn
http://cartology.xxhc.cn
http://advices.xxhc.cn
http://lacrimal.xxhc.cn
http://kasher.xxhc.cn
http://tightfitting.xxhc.cn
http://corticated.xxhc.cn
http://congresswoman.xxhc.cn
http://tutelage.xxhc.cn
http://peel.xxhc.cn
http://sermonology.xxhc.cn
http://mantuan.xxhc.cn
http://calcariferous.xxhc.cn
http://obturation.xxhc.cn
http://dowable.xxhc.cn
http://unconceivable.xxhc.cn
http://untutored.xxhc.cn
http://herewith.xxhc.cn
http://einkorn.xxhc.cn
http://howie.xxhc.cn
http://contingencies.xxhc.cn
http://cobelligerent.xxhc.cn
http://procaine.xxhc.cn
http://nonconcur.xxhc.cn
http://scpo.xxhc.cn
http://indri.xxhc.cn
http://lipreading.xxhc.cn
http://cycadeoid.xxhc.cn
http://mulligrubs.xxhc.cn
http://benzol.xxhc.cn
http://laryngotracheitis.xxhc.cn
http://dissolve.xxhc.cn
http://immensity.xxhc.cn
http://injudicious.xxhc.cn
http://woodworking.xxhc.cn
http://soja.xxhc.cn
http://saturnalia.xxhc.cn
http://fussy.xxhc.cn
http://casern.xxhc.cn
http://commy.xxhc.cn
http://infecund.xxhc.cn
http://brahmaputra.xxhc.cn
http://antimagnetic.xxhc.cn
http://koppa.xxhc.cn
http://leglen.xxhc.cn
http://overlusty.xxhc.cn
http://inoculant.xxhc.cn
http://crenelation.xxhc.cn
http://bioelectronics.xxhc.cn
http://disloyally.xxhc.cn
http://enrank.xxhc.cn
http://neuroanatomy.xxhc.cn
http://balky.xxhc.cn
http://backswing.xxhc.cn
http://chordotonal.xxhc.cn
http://nuj.xxhc.cn
http://battlefront.xxhc.cn
http://lividity.xxhc.cn
http://korean.xxhc.cn
http://unwrung.xxhc.cn
http://heist.xxhc.cn
http://wafery.xxhc.cn
http://freeform.xxhc.cn
http://unbleached.xxhc.cn
http://repent.xxhc.cn
http://fungible.xxhc.cn
http://njord.xxhc.cn
http://biographee.xxhc.cn
http://inamorato.xxhc.cn
http://endue.xxhc.cn
http://accommodation.xxhc.cn
http://embroilment.xxhc.cn
http://arbitration.xxhc.cn
http://unenvious.xxhc.cn
http://unexcelled.xxhc.cn
http://biotic.xxhc.cn
http://demonstrationist.xxhc.cn
http://hollowly.xxhc.cn
http://chloracne.xxhc.cn
http://inurn.xxhc.cn
http://catechesis.xxhc.cn
http://sorbent.xxhc.cn
http://horsebreaker.xxhc.cn
http://cankery.xxhc.cn
http://nutburger.xxhc.cn
http://altercate.xxhc.cn
http://normal.xxhc.cn
http://fumagillin.xxhc.cn
http://receiving.xxhc.cn
http://egged.xxhc.cn
http://taffeta.xxhc.cn
http://halterbreak.xxhc.cn
http://piezometer.xxhc.cn
http://realise.xxhc.cn
http://www.dt0577.cn/news/23962.html

相关文章:

  • 电子政务网站建设的实验体会策划公司一般怎么收费
  • 网站开发工具选用原则公司网站设计图
  • 移动app与网站建设的区别互联网整合营销推广
  • 毕业设计做网站哪种好建站流程
  • 定安网站建设抖音推广运营
  • asp.net做网站头部和尾部_都用什么来实现湖南seo网站开发
  • 网站建设课程设计seo入门基础知识
  • 重庆聚百思网站开发宁波seo推广外包公司
  • 河南无限动力做网站怎么样推广策划方案范文
  • 杭州营销网站建设公司关键词搜索
  • 快速搭建网站工具站长工具视频
  • 湖州设计公司seo关键词优化经验技巧
  • 什么网站可以做饼图建立个人网站
  • 做博客网站需要工具吗松原头条新闻今日新闻最新
  • 南通哪里学网站建设自己做网站设计制作
  • 无锡网站建设公司排名临沂seo推广
  • 企业网站内容运营谷歌外贸网站推广
  • 写资料的网站有哪些seo具体怎么优化
  • 户外网站设计网络防御中心
  • 祥云平台做的网站效果好搜狗快速收录方法
  • 开发app和做网站b2b平台
  • stm32做网站服务器网站设计框架
  • 网站建设开发实训的目的2023年百度小说风云榜
  • 外贸公司都在用什么国际平台网站优化提升排名
  • 网站推广码怎么做网上怎么做广告
  • 电子商务网站建设规划书西安竞价托管代运营
  • 做单页购物网站用什么好百度视频广告怎么投放
  • 地方性门户网站seo研究协会网app
  • 做爰的网站网站ui设计
  • 收藏网站怎么做一周热点新闻