Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onBeforeXXX 生命周期存在一个默认参数undefined #10863

Closed
littlezo opened this issue May 5, 2024 · 3 comments · Fixed by #10869
Closed

onBeforeXXX 生命周期存在一个默认参数undefined #10863

littlezo opened this issue May 5, 2024 · 3 comments · Fixed by #10869

Comments

@littlezo
Copy link

littlezo commented May 5, 2024

Vue version

3.4.24

Link to minimal reproduction

http://

Steps to reproduce

onBeforeXXX 钩子函数内 hook 收集剩余参数 ...args 存在一个默认的 undefined 参数
例:

onBeforeMount((..args)=>{
 args = [undefined]
})

WX20240505-224232@2x-code
WX20240505-224336-consloe

What is expected?

onBeforeMount((..args)=>{
 args = []
})

onBeforeMount 是无参的 args 应该是个空数组才对

What is actually happening?

onBeforeMount((..args)=>{
 args = [undefined]
})

onBeforeXXX 钩子函数存在 一个 undefined参数 args=[undefined]

System Info

System:
    OS: macOS 13.6.7
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 29.79 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.7.3 - ~/.nvm/versions/node/v21.7.3/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v21.7.3/bin/npm
    pnpm: 9.0.6 - /usr/local/bin/pnpm
    bun: 1.0.25 - ~/.bun/bin/bun
  npmPackages:
    vue: ^3.4.24 => 3.4.24

Any additional comments?

No response

@yyx990803
Copy link
Member

Does this have any real impact on usage?

@littlezo
Copy link
Author

littlezo commented May 7, 2024

Does this have any real impact on usage?

Yes, for the lifecycle, there is encapsulation. When external hook functions are called internally, the internal context is passed to the incoming hook function, which can result in the inability to obtain the corresponding context on the correct path

@littlezo
Copy link
Author

littlezo commented May 7, 2024

Does this have any real impact on usage?

The this instance in the above figure is not a Vue instance but a class instance, and the execution of externally passed hooks depends on the context of the this instance

sodatea pushed a commit that referenced this issue May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants