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用法
猜你喜欢
- jsPlumb+vue创建字段映射关系 2023-10-08
- layui数据表格以及传数据方式 2022-12-13
- 基于CORS实现WebApi Ajax 跨域请求解决方法 2023-02-14
- 关于 html:如何从 css 表中删除边距和填充 2022-09-21
- javascript 判断当前浏览器版本并判断ie版本 2023-08-08
- ajax实现输入提示效果 2023-02-14
- 深入浅析AjaxFileUpload实现单个文件的 Ajax 文件上传库 2022-12-15
- 1 Vue - 简介 2023-10-08
- JS实现左侧菜单工具栏 2022-08-31
- vue keep-alive 2023-10-08