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

网站设计咨询电话seo外链优化培训

网站设计咨询电话,seo外链优化培训,开发公司排名,网站建设的总体目标在 Vue 2 和 Vue 3 中#xff0c;watch 用于监听数据的变化并执行相应的逻辑。虽然两者的核心功能相同#xff0c;但在语法和使用方式上有一些区别。以下是 Vue 2 和 Vue 3 中使用 watch 的详细说明#xff1a; Vue 2 中的 watch 在 Vue 2 中#xff0c;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/14593743/

相关文章:

  • mui做的h5网站案例学校网站建设价格
  • 网页制作创建站点内容推广普通话宣传海报
  • 网站建设引入谷歌地图端游网络游戏排行榜
  • 泉港网站建设推广服务公司asp 网站开发实例教程
  • 网站关键词引流帮企业做网站的公司
  • 哪几个网站做acm题目站长seo查询工具
  • 宝安做棋牌网站建设哪家便宜网页图片不能正常显示的原因
  • 食品网站建设客户需求调查表互联网网站如何做
  • c 高性能网站开发北京电力建设公司贴吧
  • 四大门户网站的优缺点海外做淘宝网站
  • 网站开发答辩知识点ftp上直接编辑wordpress
  • 苏州模板做网站南山网站设计方案
  • php网站后台管理系统竞价排名机制
  • 免费的写作网站服装网站建设平台
  • 网站qq临时会话代码主播网站怎么建设
  • 温州建设工程信息网站网络营销软件哪个好用
  • 免费网站建设多少钱怎么查询企业邮箱账号
  • 零库存品牌童装杭州网站建设企业网站策划书
  • 建设单位到江川区住房和城乡建设局网站苏州网站优化排名推广
  • 注册免费微网站广州室内装修设计
  • 怎么样推广自己的网站网络网站建设10大指标
  • 怎么查询网站是否收录wordpress建站费用
  • 网站放音乐代码网站建设投标方案
  • 最新互联网项目平台网站wordpress 判断页面id
  • 网站开发员一月多少工资win7做系统网站哪个好
  • 林州网站建设制作做网站项目计划书
  • 比较大的做网站的公司推广计划书范文
  • 人与狗做的网站谁有那个网站的公众后推广做的好
  • 广西城乡住房建设厅网站中讯科技-运城网站建设
  • 网站建设开票多少个点长沙网站网站建设