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

useMounted does not work in vue2.7 #3803

Closed
7 tasks done
yanbowe opened this issue Feb 21, 2024 · 10 comments · Fixed by #3802
Closed
7 tasks done

useMounted does not work in vue2.7 #3803

yanbowe opened this issue Feb 21, 2024 · 10 comments · Fixed by #3802

Comments

@yanbowe
Copy link
Contributor

yanbowe commented Feb 21, 2024

Describe the bug

由于getCurrentInstance()在vue2.7和vue3获取的instance实例结果不同,在vue2.7中 onMounted第二个参数的值应该为instance?.proxy,设置为instance会导致报错,由于vue-demi中的onMounted的参数类型不支持ComponentPublicInstance,先设置为null保证在vue2.7中可以正常运行

Reproducti

on

https://github.com/vueuse/vueuse/releases/tag/v10.8.0

System Info

System:
    OS: macOS 12.6
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 54.02 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.20.1 - /usr/local/bin/node
    Yarn: 1.22.18 - /usr/local/bin/yarn
    npm: 8.19.4 - /usr/local/bin/npm
  Browsers:
    Chrome: 121.0.6167.184
    Safari: 16.0
  npmPackages:
    @vueuse/core: 10.8.0 => 10.8.0 
    vue: 2.7.16 => 2.7.16

Used Package Manager

npm

Validations

@TouchSek
Copy link

+1

@dylanFdvhuset
Copy link

+1 when using useWindowSize

@begedin
Copy link
Contributor

begedin commented Feb 28, 2024

After updating to 10.9.0, i still seem to be experiencing it with useVirtualList

[Vue warn]: onMounted is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup().
      at warn$2 (node_modules/vue/dist/vue.common.dev.js:5054:21)
      at Object.onMounted (node_modules/vue/dist/vue.common.dev.js:3912:13)
      at useMounted (node_modules/@vueuse/core/index.cjs:503:13)
      at useSupported (node_modules/@vueuse/core/index.cjs:511:21)
      at useResizeObserver (node_modules/@vueuse/core/index.cjs:2523:23)
      at useElementSize (node_modules/@vueuse/core/index.cjs:2681:27)
      at useVirtualListResources (node_modules/@vueuse/core/index.cjs:6763:16)
      at useVerticalVirtualList (node_modules/@vueuse/core/index.cjs:6889:21)
      at useVirtualList (node_modules/@vueuse/core/index.cjs:6747:123)

@xsfour
Copy link

xsfour commented Feb 28, 2024

先设置为null保证在vue2.7中可以正常运行

onMounted 的第二个参数设置为 null 似乎并没有使 useMounted 生效,始终会报 warning。
https://github.com/vuejs/vue/blob/bed04a77e575d6c4c1d903f60087dca874f7213e/src/v3/apiLifecycle.ts#L10

@yanbowe
Copy link
Contributor Author

yanbowe commented Feb 29, 2024

先设置为null保证在vue2.7中可以正常运行

onMounted 的第二个参数设置为 null 似乎并没有使 useMounted 生效,始终会报 warning。 https://github.com/vuejs/vue/blob/bed04a77e575d6c4c1d903f60087dca874f7213e/src/v3/apiLifecycle.ts#L10

应该设置为void 0

@xsfour
Copy link

xsfour commented Feb 29, 2024

准确的是不是还是应该传instance?.proxy?类型用as来规避是不是就好了

@nguyentranchung
Copy link

useDark, useClipboard still have problem

[Vue warn]: onMounted is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup().

@roitto
Copy link

roitto commented Mar 14, 2024

Yup, still spams onMounted is called when there is no active component instance to be associated with. warnings to the console. Seems that the PR #3830 fixes the issue.

@Ttou
Copy link

Ttou commented Mar 19, 2024

useFullscreen still have problem

@kooriookami
Copy link

When to release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants