<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,然后子组件里面监听