1. Start with the code
<script> import { reactive ,toRefs, ref ,watch} from "vue"; import { useRouter } from "vue-router"; export default { setup() { const state = reactive({ password: null, username: null, }); // const router = useRouter(); // const goto_home = (() => { // router.replace( '/userList') // }) const affirm = ()=>{ console.log('enter') } Watch (()=>state. Username, (newValue, oldValue) => {console.log(" changed ",newValue,oldValue,state); }); return { affirm, ... toRefs(state) }; }}; </script>
This is the right way to listen
2. If you are listening to all of them
Watch (state, (newValue, oldValue) = bb0 {// Listen to console.log(" Count changed ",newValue,oldValue,state); });
NewValue is the same as oldValue (both are modified values)
Recommended option 1, where you can listen for pre - and post-modification values