Subscribe on changes!

After modifying the value of defineModel, I expected emit to pass the latest value of the model to the function of the parent component for use, but found that it was still the old value.

avatar
Feb 19th 2024

Vue version

3.4

Link to minimal reproduction

https://play.vuejs.org/#eNrFWFtvG0UU/iuDVbSOlKydRn5xHQMteSjiUtGqL3GUrtez9jbrmdXurONgWaqqClJBIAVEQ+EBVXmk7QuqaBvEj8F2lKf+Bc5cdtbrG3ao1EhRds755pwzZ85t0sl84PtmK8KZYqYU2oHrMxRiFvnlCnGbPg0Y6qAAWzZzW3gZvhzURU5Am8iATYYGXaFNX9HNHF9wmcYlzb9KCA5SIE2JkRViUxIy1KQ17KF1rTXbqRCEXA4vIsfyQlwh3aUE79F6OAzf3AKmZLVwELqUCK6TNVbNvJk3hrbaDYvU8U2Nyi6h9TKS+hyUVdvNluVFGK2vr6NYhMSgWEGMQMZFwefMLsJg6jQ5EjdbTmFOOYUZctbmtEfiZstJ2TMNKB0kgHBNiaspueK59g53ssAuI9zChC2jbSUCvpyI2MkN8Hs1IxI2XIfJGNDqiskuRbc8t1bkf9SBRBCZImjQe8joP3vRe/mlgYrIOPvxZ/6pNjbDehHd2rzQIXgXfWgxnF0yGf2Y2paHb7hNfJ0FLqlnl7pbgImVdrek8fLURXShIz66yI6CAOicMmRA95ZwB8Qd+KOUk1kG+QULhpu+B1phhVDJR7ZnheF6JcNcP6xkyv2/fkDgUHR6f3/w6++Dh89fn3zTf3J4+upe79VzAHOH9l5+DYv+4YP+8U+9k9/O7nx/+uie8kTvz4PB0bP+d0eDX/7oH34LDBCwZraVwN7fT/vHB+CNwZPjs4dPzx4f/XPnbinHcx+sqQbqLzejf/9A7nl98qiUq5Y7HZ1cXTgVwELfIihkex4G+3fdGmsU0Wreb1+Cc8ChgavERYzBrveF9QBN5SA/8/5Xg4PHUhloEuiyNiapI60V14HtOsWT7KxkgCn8D/yhewC61qrCkUOlAKCJ3UDJjaviIT9Bn8r2c+oTuxfWB1n4P/QVFtKnqsc59YndC+s7//nE7un63sghVBzy2lSMCTo4a25LZzBHQDTLKgOZ3VpxaCDpiDpCAEgtxvBNIJi6EooFL2lbIAJSTa8h2dAKUhSoXbDW+ZoD9fBVyg0VFViKlEShTX1cA4rJS4sssDb1KLTUANeg+4pSbYpeKpgqgwv5d4EJddIlKw3s1htQ3FYLIq0TCfXA2hNr36rVoFzGiQ+UKg1qvG+v+m0UUn6CqmfZO2mFJi++aZOq2LYtPwp8D0sslBB+kHJmOcPgMMRx6+btkBKYW8ROKCRw1a6Hg898Bk4E7xbjJlXJWJ5Hdz8SNBZA84npdgPbOxPot8M2p1Uy1wIc4qCFKxnNY1ZQx0yyN65/itvwrZkQWZEH6BnMzzE4IuI2StjliNTA7CGcsPaqGJzAmzfCjTbDhEeGNlQ0FIGHDIowj/JpR0/MXTPX4r4MXoxHr+mD3zlmthp2XII/4atsB7E9H7rjZUo9DL2BN0DJvxZQP8xuGireDT6wxZJw02Va0AYsAAj3JPNSAme10OGkT2U7T7Ykq9UXEOOOBa075KHnU5cwHEDXkg7UxWFkbFESxLjCbc4aAmgAZyJO1YJS4sPRXIU7Sfl39kSensPPcRUS7fOr0OhJFzNpkha74nKlMXNc3dgsKLy06NQdgDsCEtu0vbqd384rSQtP3iOyLi4sa2j6niCrMLeskQl8RNbaQnbJPjpL1gS75nRuaqpPiZxwnxIF5f2meh+8I1uvsFU2lmQN7BgpWOm0ilk6s+JTxr1k3KL8PBalDADn8fIKTwbx0IT3Al++CUPhaicbKqLkrRg6BExsVSE93dZJTk2rnNfQOa2Z6jkRmmPWcAxUOT5ZZIdlGqvqh/8DYNTksbCUvzIj5rBTFSi99T8eesODYtNyeR8aH0L17FjmHaGITu++GOw/iMc9wdDP4dRzLAUR5gqAbAyLD4zcQBWSoz2S+xHGC5gNGQUL9dQ3MjzOMxbKKVRPgNX4IhxK2ErofgHd62JB7fagvyTTaCwzgkFtJcQetoFKKBkZHKHBdv8Fnf5yuQ==

Steps to reproduce

见链接里面的代码

What is expected?

期望的到解答defineModel 的值赋值之后不能立刻获取最新的值?

What is actually happening?

const model = defineModel({ type: Boolean })

const version_1_0_0 = (event) => { console.log(model.value,'11111111') model.value = !model.value; //这里的modal.value还是修改前的值 emit('click', model.value, event, '1.0.0'); }

System Info

No response

Any additional comments?

No response

avatar
Feb 20th 2024
- v-model="model.inner"
+ model.inner = !model.inner;
avatar
Feb 22nd 2024
- v-model="model.inner"
+ model.inner = !model.inner;

model.inner = !model.inner; 之后我期望拿到的是最新的修改值,然后去进行emit 执行某个业务逻辑,但是最终结果是model.inner = !model.inner;这段代码貌似会是异步的