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

个人网站建设与维护微信广告投放收费标准

个人网站建设与维护,微信广告投放收费标准,做网站的相关教程,山东建设厅网站作用:监视数据的变化(和Vue2中的watch作用一致)特点:Vue3中的watch只能监视以下四种数据: ref定义的数据。reactive定义的数据。函数返回一个值(getter函数)。一个包含上述内容的数组。 我们在V…
  • 作用:监视数据的变化(和Vue2中的watch作用一致)
  • 特点:Vue3中的watch只能监视以下四种数据
  1. ref定义的数据。
  2. reactive定义的数据。
  3. 函数返回一个值(getter函数)。
  4. 一个包含上述内容的数组。

我们在Vue3中使用watch的时候,通常会遇到以下几种情况:

ref定义的基本类型

<template><div class="person"><h2>当前求和{{ sum }}</h2><button @click="changeAddOne">点击加一</button></div>
</template><script lang="ts" setup name="Person">
import { computed,watch, ref, watchEffect } from 'vue'// 数据
let sum = ref(0);// 方法
function changeAddOne() {sum.value++;
}// 监视 watch(谁,回调函数)
watch(sum, (newValue, oldValue) => {console.log('sum发生变化了', newValue, oldValue);
});
</script>

watch监视里面的ref数据不需要.value

主动停止监视:

<template><div class="person"><h2>当前求和{{ sum }}</h2><button @click="changeAddOne">点击加一</button></div>
</template><script lang="ts" setup name="Person">
import { computed,watch, ref, watchEffect } from 'vue'// 数据
let sum = ref(0);// 方法
function changeAddOne() {sum.value++;
}// 监视 watch(谁,回调函数)
const stopWatch = watch(sum, (newValue, oldValue) => {console.log('sum发生变化了', newValue, oldValue);if(newValue >= 10) {stopWatch();}
});
</script>

ref定义的对象数据

监视ref定义的【对象类型】数据:直接写数据名,监视的是对象的【地址值】,若想监视对象内部的数据,要手动开启深度监视。

注意:

  • 若修改的是ref定义的对象中的属性,newValueoldValue 都是新值,因为它们是同一个对象。
  • 若修改整个ref定义的对象,newValue 是新值, oldValue 是旧值,因为不是同一个对象了。
<template><div class="person"><h2>Person</h2><p>姓名:{{ person.name }}</p><p>年龄:{{ person.age }}</p><button @click="changeAge">年龄+1</button></div>
</template><script lang="ts" setup name="Person">
import { computed,watch, ref, watchEffect } from 'vue'// 数据
let person = ref({name: '张三',age: 18
});
// 方法
function changeAge() {person.value.age++;
}// 监视 watch(谁,回调函数)
// 监视的是对象的地址值,若想监视对象内部的属性,需要手动开启深度监视 - deep: true
watch(person, (newVal, oldVal) => {console.log('watch:', newVal, oldVal);
}, {deep: true, immediate: true});
</script>

watch的参数:

  • 第一个参数:被监视的数据
  • 第二个参数:监视的回调
  • 第三个监视:配置对象(deep, imediate)

reactive定义的对象数据

reactive默认监视开启深度监视。

<template><div class="person"><h2>Person</h2><p>姓名:{{ person.name }}</p><p>年龄:{{ person.age }}</p><button @click="changeAge">年龄+1</button></div>
</template><script lang="ts" setup name="Person">
import { computed,watch, ref, watchEffect, reactive } from 'vue'// 数据
let person = reactive({name: '张三',age: 18
});
// 方法
function changeAge() {person.age++;
}// 监视 watch(谁,回调函数)
// 默认开始深度监视 
watch(person, (newVal, oldVal) => {console.log('watch:', newVal, oldVal);
}, {immediate: true});
</script>

监视ref/reactive定义的对象类型中某一个属性

监视refreactive定义的【对象类型】数据中的某个属性,注意点如下:

  1. 若该属性值不是【对象类型】,需要写成函数形式。
  2. 若该属性值是依然是【对象类型】,可直接编,也可写成函数,建议写成函数。

结论:监视的要是对象里的属性,那么最好写函数式,注意点:若是对象监视的是地址值,需要关注对象内部,需要手动开启深度监视。

<template><div class="person"><h2>Person</h2><p>姓名:{{ person.name }}</p><p>年龄:{{ person.age }}</p><button @click="changeAge">年龄+1</button><p>车:{{ person.car.c1 }}</p><button @click="changeCarC1">修改第一量车</button></div>
</template><script lang="ts" setup name="Person">
import { computed,watch, ref, watchEffect, reactive } from 'vue'// 数据
let person = reactive({name: '张三',age: 18,car:{c1:'宝马',c2:'奔驰'}
});
// 方法
function changeAge() {person.age++;
}
function changeCarC1() {person.car.c1 += '---';
}
// 监视 watch(谁,回调函数)
// 默认开始深度监视 
watch(() => {return person.age
}, (newVal, oldVal) => {console.log('age:', newVal, oldVal);
});
</script>
<template><div class="person"><h2>Person</h2><p>姓名:{{ person.name }}</p><p>年龄:{{ person.age }}</p><button @click="changeAge">年龄+1</button><p>车:{{ person.car.c1 }}</p><button @click="changeCarC1">修改第一量车</button></div>
</template><script lang="ts" setup name="Person">
import { computed,watch, ref, watchEffect, reactive } from 'vue'// 数据
let person = reactive({name: '张三',age: 18,car:{c1:'宝马',c2:'奔驰'}
});
// 方法
function changeAge() {person.age++;
}
function changeCarC1() {person.car.c1 += '---';
}
// 监视 watch(谁,回调函数)
// 默认开始深度监视 
watch(() => {return person.car
}, (newVal, oldVal) => {console.log('car:', newVal, oldVal);
}, {deep:true});
</script>

多个数据?

<template><div class="person"><h2>Person</h2><p>姓名:{{ person.name }}</p><p>年龄:{{ person.age }}</p><button @click="changeAge">年龄+1</button><p>车:{{ person.car.c1 }}</p><button @click="changeCarC1">修改第一量车</button></div>
</template><script lang="ts" setup name="Person">
import { computed,watch, ref, watchEffect, reactive } from 'vue'// 数据
let person = reactive({name: '张三',age: 18,car:{c1:'宝马',c2:'奔驰'}
});
// 方法
function changeAge() {person.age++;
}
function changeCarC1() {person.car.c1 += '---';
}
// 监视 watch(谁,回调函数)
// 默认开始深度监视 
watch(() => {return [person.car, person.age]
}, (newVal, oldVal) => {console.log('car:', newVal, oldVal);
}, {deep:true});
</script>

文章转载自:
http://dinncocracking.bkqw.cn
http://dinncowoodenness.bkqw.cn
http://dinncodishpan.bkqw.cn
http://dinncoassyrian.bkqw.cn
http://dinncosatyrical.bkqw.cn
http://dinncovimen.bkqw.cn
http://dinncostockcar.bkqw.cn
http://dinncolyrebird.bkqw.cn
http://dinncouss.bkqw.cn
http://dinncopulsant.bkqw.cn
http://dinncoexpatiation.bkqw.cn
http://dinncoantiscriptural.bkqw.cn
http://dinncodivest.bkqw.cn
http://dinncothundercloud.bkqw.cn
http://dinncoprecipitable.bkqw.cn
http://dinncobrutality.bkqw.cn
http://dinncofoiled.bkqw.cn
http://dinnconumerary.bkqw.cn
http://dinncocrabgrass.bkqw.cn
http://dinncodaff.bkqw.cn
http://dinncosquiffer.bkqw.cn
http://dinncovesper.bkqw.cn
http://dinncosuccinctness.bkqw.cn
http://dinncoannexation.bkqw.cn
http://dinncodauphine.bkqw.cn
http://dinncoredrill.bkqw.cn
http://dinncopressroom.bkqw.cn
http://dinncofog.bkqw.cn
http://dinncojerrican.bkqw.cn
http://dinnconosy.bkqw.cn
http://dinncoenvironmentalism.bkqw.cn
http://dinncorabbit.bkqw.cn
http://dinncocouncillor.bkqw.cn
http://dinncocompaginate.bkqw.cn
http://dinncoantenniform.bkqw.cn
http://dinncotheoretician.bkqw.cn
http://dinnconitrification.bkqw.cn
http://dinncountwine.bkqw.cn
http://dinncohubble.bkqw.cn
http://dinncoplanktology.bkqw.cn
http://dinncobouncing.bkqw.cn
http://dinncogrenadier.bkqw.cn
http://dinncopseudopodium.bkqw.cn
http://dinncofeebleness.bkqw.cn
http://dinncophthisis.bkqw.cn
http://dinncohandlist.bkqw.cn
http://dinncovexillary.bkqw.cn
http://dinncooverpowering.bkqw.cn
http://dinncoforcipressure.bkqw.cn
http://dinncoeuropeanist.bkqw.cn
http://dinncopeloponnesus.bkqw.cn
http://dinncoshipboard.bkqw.cn
http://dinncoillustrative.bkqw.cn
http://dinncoflushing.bkqw.cn
http://dinncoscrewdriver.bkqw.cn
http://dinncohesitancy.bkqw.cn
http://dinncoscr.bkqw.cn
http://dinncozara.bkqw.cn
http://dinncobattleship.bkqw.cn
http://dinncoovergrow.bkqw.cn
http://dinncootb.bkqw.cn
http://dinncocomet.bkqw.cn
http://dinncoectochondral.bkqw.cn
http://dinncohyperirritability.bkqw.cn
http://dinncochorography.bkqw.cn
http://dinncotrenchplough.bkqw.cn
http://dinncodichogamic.bkqw.cn
http://dinncosauciness.bkqw.cn
http://dinncodirigisme.bkqw.cn
http://dinncounfound.bkqw.cn
http://dinncostodginess.bkqw.cn
http://dinncosociogram.bkqw.cn
http://dinncogrutten.bkqw.cn
http://dinncoversemonger.bkqw.cn
http://dinncobuffer.bkqw.cn
http://dinncoepizootiology.bkqw.cn
http://dinncoyoni.bkqw.cn
http://dinncoemperor.bkqw.cn
http://dinncoairship.bkqw.cn
http://dinncoembowel.bkqw.cn
http://dinncoubiquity.bkqw.cn
http://dinncorevolutionist.bkqw.cn
http://dinncocomprize.bkqw.cn
http://dinncoposted.bkqw.cn
http://dinncohemishere.bkqw.cn
http://dinncoyttriferous.bkqw.cn
http://dinncohorace.bkqw.cn
http://dinncocoextend.bkqw.cn
http://dinncoretroject.bkqw.cn
http://dinncotandjungpriok.bkqw.cn
http://dinncoconsciousness.bkqw.cn
http://dinncoglandiferous.bkqw.cn
http://dinncoefficiently.bkqw.cn
http://dinncoshave.bkqw.cn
http://dinncokathi.bkqw.cn
http://dinncotheological.bkqw.cn
http://dinncomatrilocal.bkqw.cn
http://dinncoimmorally.bkqw.cn
http://dinncophonetics.bkqw.cn
http://dinncoheavily.bkqw.cn
http://www.dinnco.com/news/141442.html

相关文章:

  • 时时彩网站开发定制服务外包平台
  • 一个交易网站开发的成本是多少钱市场营销公司有哪些
  • 营销型网站建设的资讯百度安装下载
  • 全国高速公路施工建设有没有网站百度明星搜索量排行榜
  • 娄底网站建设最专业百度seo优化包含哪几项
  • asp装修网站源码聚名网域名注册
  • 做网站什么硬盘好怎么把平台推广出去
  • 微小店适合卖做分类网站吗今天最新新闻10条
  • 宽带办理多少钱一个月成都网站seo推广
  • 亿唐网不做网站做品牌域名备案查询站长工具
  • 软件设计学什么宁波seo专员
  • 新闻发布网站建设实训郑州seo顾问外包
  • 做网站要那些设备付费推广方式有哪些
  • 瓦房店网站建设百度指数在哪里看
  • 毕设做网站和app自动点击器软件
  • 有出国做飞机求同行的网站灰色词seo推广
  • 政府网站建设 江苏省成都网站制作关键词推广排名
  • wordpress主题目录位置深圳网站seo推广
  • asp建的网站上传文章电脑培训学校课程
  • 广州专门做网站的公司有哪些职业培训机构
  • 第一站商城如何注册自己的网站
  • 做网站模版与定制的区别百度小程序入口
  • 石家庄网站建设批发全网媒体发布平台
  • 网站设置了 不能复制百度推广费
  • 网站术语百度网盘app下载安装手机版
  • 网站开发外包计入什么科目网站源码建站
  • 金华建站模板百度一下百度网页官
  • 海外贸易平台网页关键词排名优化
  • wordpress使用密码错误深圳优化公司义高粱seo
  • 如何选择网站公司营销活动推广策划