templatediv{{propContent}}/div/templatescriptimport { watchEffect, watch, ref } from vue;export default {name: ,components: {},mixins: [],props: {listArr: {type: Object},list1: {type:...
<template> <div>{{propContent}}</div> </template> <script> import { watchEffect, watch, ref } from "vue"; export default { name: "", components: {}, mixins: [], props: { listArr: { type: Object }, list1: { type: String } }, setup(props, content) { let propContent = ref(0); watch( () => props.list1, (val, oldval) => { /* ... */ propContent.value = parseInt(val) + 2; console.log("val", val); console.log("oldval", oldval); console.log("propContent", propContent); }, { immediate: true, deep: true } ); // watchEffect(() => { // console.log("watchEffect", props); // propContent.value = parseInt(props.list1) + 2; // console.log("propContent", propContent); // }); return { propContent }; } }; </script> <style lang="less" scoped> </style>
从父组件传了input框的(可以动态改)
list1,然后子组件里面监听
沃梦达教程
本文标题为:vue3.0之watchEffect,watch用法
基础教程推荐
猜你喜欢
- uniapp开发微信小程序自定义顶部导航栏功能实例 2022-10-21
- Javascript Bootstrap的网格系统,导航栏和轮播详解 2023-08-11
- 关于Ajax跨域问题及解决方案详析 2023-02-23
- 使用ajax跨域调用springboot框架的api传输文件 2023-02-23
- 在实战中可能碰到的几种ajax请求方法详解 2023-02-01
- Ajax发送和接收请求 2022-12-15
- JS滚动到顶部踩坑解决记录 2023-07-10
- HTML clearfix清除浮动讲解 2022-11-20
- Ajax+smarty技术实现无刷新分页 2022-12-15
- cocos creator游戏实现loading加载页面,游戏启动加载动画 2022-10-29