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

网站建设难吗宣传推广计划怎么写

网站建设难吗,宣传推广计划怎么写,承德做网站优化,哪个网站做二手叉车回收好在 Vue 2 和 Vue 3 中,watch 用于监听数据的变化并执行相应的逻辑。虽然两者的核心功能相同,但在语法和使用方式上有一些区别。以下是 Vue 2 和 Vue 3 中使用 watch 的详细说明: Vue 2 中的 watch 在 Vue 2 中,watch 是通过选项式…

在 Vue 2 和 Vue 3 中,watch 用于监听数据的变化并执行相应的逻辑。虽然两者的核心功能相同,但在语法和使用方式上有一些区别。以下是 Vue 2 和 Vue 3 中使用 watch 的详细说明:

Vue 2 中的 watch

在 Vue 2 中,watch 是通过选项式 API 实现的,通常在组件的 watch 选项中定义。

【基本用法】

export default {data() {return {message: 'Hello Vue 2',count: 0,};},watch: {// 监听 message 的变化message(newVal, oldVal) {console.log('message changed:', newVal, oldVal);},// 监听 count 的变化count(newVal, oldVal) {console.log('count changed:', newVal, oldVal);},},
};

【监听对象属性】
如果需要监听对象的某个属性,可以使用字符串形式的键名:

export default {data() {return {user: {name: 'Alice',age: 25,},};},watch: {'user.name'(newVal, oldVal) {console.log('user.name changed:', newVal, oldVal);},},
};

【深度监听】
如果需要监听对象或数组内部的变化,可以设置 deep: true:

export default {data() {return {user: {name: 'Alice',age: 25,},};},watch: {user: {handler(newVal, oldVal) {console.log('user changed:', newVal, oldVal);},deep: true, // 深度监听},},
};

【立即执行】
如果需要监听器在创建时立即执行一次,可以设置 immediate: true:

export default {data() {return {message: 'Hello Vue 2',};},watch: {message: {handler(newVal, oldVal) {console.log('message changed:', newVal, oldVal);},immediate: true, // 立即执行},},
};

Vue3中的watch

在 Vue 3 中,watch 是通过 Composition API 实现的,使用 watch 函数来定义监听器。
【基本用法】

import { ref, watch } from 'vue';export default {setup() {const message = ref('Hello Vue 3');const count = ref(0);// 监听 message 的变化watch(message, (newVal, oldVal) => {console.log('message changed:', newVal, oldVal);});// 监听 count 的变化watch(count, (newVal, oldVal) => {console.log('count changed:', newVal, oldVal);});return {message,count,};},
};

【监听多个数据】

import { ref, watch } from 'vue';export default {setup() {const firstName = ref('Alice');const lastName = ref('Smith');// 监听 firstName 和 lastName 的变化watch([firstName, lastName], ([newFirstName, newLastName], [oldFirstName, oldLastName]) => {console.log('firstName or lastName changed:', newFirstName, newLastName);});return {firstName,lastName,};},
};

【监听对象属性】

import { ref, watch } from 'vue';export default {setup() {const user = ref({name: 'Alice',age: 25,});// 监听 user.name 的变化watch(() => user.value.name,(newVal, oldVal) => {console.log('user.name changed:', newVal, oldVal);});return {user,};},
};

【深度监听】
在 Vue 3 中,默认情况下 watch 是浅层的。如果需要深度监听,可以设置 { deep: true }:

import { ref, watch } from 'vue';export default {setup() {const user = ref({name: 'Alice',age: 25,});// 深度监听 user 对象watch(user,(newVal, oldVal) => {console.log('user changed:', newVal, oldVal);},{ deep: true });return {user,};},
};

【立即执行】
如果需要监听器在创建时立即执行一次,可以设置 { immediate: true }:

import { ref, watch } from 'vue';export default {setup() {const message = ref('Hello Vue 3');// 立即执行监听器watch(message,(newVal, oldVal) => {console.log('message changed:', newVal, oldVal);},{ immediate: true });return {message,};},
};
http://www.hkea.cn/news/205420/

相关文章:

  • 怎么做外贸网站的邮箱签名搜索引擎优化是指什么
  • 网页制作基础教程免费邯郸网站seo
  • phpcms做网站感想漯河seo推广
  • 公司部门kpi绩效考核指标模板河北百度seo软件
  • 印团网网站是哪家做的唯尚广告联盟
  • 网红营销网站seo综合查询怎么用的
  • 西安地区网站建设云推广
  • wordpress个人站2020年关键词排名
  • 网站建设企业公司石家庄新闻头条新闻最新今天
  • 道滘镇做网站百度统计
  • qq空间做宣传网站怎样建立自己的网站平台
  • 做设计一般用的素材网站是什么意思刷网站排名软件
  • 帮人做兼职的网站吗青岛seo服务哪家好
  • 贷款类网站怎样做网络营销的推广
  • 乐清做网站哪家好税收大数据
  • 校园网站建设需求天津放心站内优化seo
  • 哈尔滨微网站建设热搜在哪里可以看
  • 网站用oracle做数据库福州seo推广服务
  • 康保县城乡建设委员会网站营销型网站重要特点是
  • 手机做网站的步骤跨境电商有哪些平台
  • 请人做网站要多少网络事件营销
  • 网站页脚有什么作用厦门seo哪家强
  • 东莞百度提升优化优化推广网站推荐
  • 查企业网站有哪些站长统计app软件
  • 做a高清视频在线观看网站济源新站seo关键词排名推广
  • 刚做的网站怎么搜索不出来百度seo收录软件
  • 视频拍摄app站长工具seo综合查询广告
  • 新闻单位建设网站的意义武汉seo推广优化
  • 低价网站公司软文怎么写
  • 东莞市建设公共交易中心网站百度官网首页