Subscribe on changes!

子组件定义的 computed get, set 值更改不是同步的,是设计如此吗?

avatar
Jul 20th 2022

Vue version

3.2.37

Link to minimal reproduction

https://sfc.vuejs.org/#eNp9VEFv0zAU/itPuSTT2gQ4lnYCAQc4IA6Iy7JDmrpdRmJHttMJRZU4IIGEhjhMmtgJcUJC4oI0gRjan1nbI3+BZztx06w0aSXb7/n73vc+x6VzP8/9aUGcntMXMU9yCYLIIt8LaZLljEsogZMxzGDMWQYupro29KAQkmWPaV7IKuwHjTWFi8kAIY0ZFRIyIkQ0ITBQkJ57SNKUuTshVW8/MPRIjBNJsjyNJMEZQL/JM+1mbETSQehUaKEDwV5/yPegLC3DbKYQLYrTcUzJ3SzK/SPBKOotdWlVQIROD/SKWsPC1Tx0DqXMRS8IxDhWao6Ez/gkwJHPCyqTjPhEZN0hZ8eCcAQOnU4DI8DFKeFdTuiIcMK3YbZSb+AqWBQ1QymtFm+wDqBpXgdilmEyGbVsrH3JOcsFujIi44SSZ2rm7bu6zy+iFFMP0CSTSrJE2sxHOFGZRT7CLvdaG5rOjxMu5NMos94/YYdUWW/CabQefciIORfV7iJNq3CtxNNeBQFMiJTYWZzgyNupPeTYCU5XvP5U1QW74OK7awnNsu6tNg4BsYcVII48So61Igu834LstLAOsMh6ky/yNJEeUqIYY58e4N8IM0W1VW0Soi3yVx1WGFXNqkwNZPcok7wNrnQM4VoxthbKjuv2uzt37TJujl7hyVkL4W9c0FgmjEIURWDL1fhVrwfg3r6jHldtAUVgI408jSc1G0uJn7KJ5y6/vZ+f/Fiev5m/voRBXbfJ1wVo1c/x+2OF9JB9gF+/0V4X/D8q9axxzX9fLM4utnLNOnBLN0133R7HlU7sQQRDfCqpawTXP0+u/1wtT7+aj2f+7tPi7LNhRTbXniec3Dhbbn24MLh+zlQ96KE2Y9vdmahrwuheXZ3m1Os7JTBpw0JKNPNenCbxS8xAQaGjQ4AVv12cfMH26MzApFbb8Nq9vvq+OP01//ih6drfy/OyRMfVRVzlGckqb5VRmdW+rmf/AIU1X6k=

Steps to reproduce

点击按钮 “切换值” 就可以看到值没同步修改。

使用了 emit 修改值的没有同步修改, 直接当前页面的值 会同步修改,这个是 这样设计的吗?

What is expected?

修改值后应该同步修改当前值。

What is actually happening?

修改值后没有同步修改

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
    Memory: 5.22 GB / 15.92 GB
  Binaries:
    Node: 16.14.0 - D:\node\v16.14.0-win-x64\node.EXE
    npm: 8.3.1 - D:\node\v16.14.0-win-x64\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (103.0.1264.62), ChromiumDev (104.0.1278.2)
    Internet Explorer: 11.0.22000.120

Any additional comments?

我定义了一个组件,参考了 官方文档 下面那种 computed 的写法,我在修改了 computed 定义的值后,使用了 修改后的值进行判断, 发现值还是 修改前的值。

avatar
Jul 20th 2022

This is expected. the value would only update asynchronously once the parent has triggered a re-render of the child.

If you need support in how to deal with this situation, please use our Discord server or stackoverflow.